当前位置: 编程技术>移动开发
本页文章导读:
▪StoryBoard学习(六):使用notification广播实现视图跳转传递数据 StoryBoard学习(6):使用notification广播实现视图跳转传递数据
StoryBoard学习(6):使用notification广播实现视图跳转传递数据
转载自 http://blog.csdn.net/mad1989/article/details/7919504
广播机制.........
▪ 一般情况上安装APK 一般情况下安装APK
private void installNormal() {
LogUtils.log(TAG, LogUtils.getThreadName());
setStatus(State.INSTALLING);
String rootpath = Environment.getExternalStorageDirectory().getPath()
+ File..........
▪ Objective-C 下传图片至服务端 Objective-C 上传图片至服务端
NSURL *url = [NSURL URLWithString: urlString ];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];NSMutableData *postData = [NSMutableData dataWithContentsOfFile:imagePath].........
[1]StoryBoard学习(六):使用notification广播实现视图跳转传递数据
来源: 互联网 发布时间: 2014-02-18
StoryBoard学习(6):使用notification广播实现视图跳转传递数据
StoryBoard学习(6):使用notification广播实现视图跳转传递数据
转载自 http://blog.csdn.net/mad1989/article/details/7919504
广播机制分为:注册----发送------------接收(接收方),具体请看一下代码。
1,在要发送数据的视图页面.m文件处理发送逻辑的方法里注册+发送
- (IBAction)pressed:(id)sender {
// [self performSegueWithIdentifier:@"second" sender:self];
NSLog(@"send message:%@",firstField.text);
//页面跳转传值方法二:利用notification
NSDictionary *dicts = [NSDictionary dictionaryWithObjectsAndKeys:@"one1",@"one",@"two2",@"two",@"three3",@"three", nil];
//注册(第一步)
NSNotification *notification =[NSNotification notificationWithName:@"mynotification" object:firstField.text];
//发送(第二步)
[[NSNotificationCenter defaultCenter] postNotification:notification];
//注册+发送也可以一行完成(等效于以上两行)
[[NSNotificationCenter defaultCenter] postNotificationName:@"mynotification2" object:dicts];//发送一个字典过去
}
notificationWithName:参数的值是自己定义,接收方以此名称为接收标识。
2,在跳转后,接收数据视图页面.m文件中处理逻辑的方法里 接收
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
//接受端:接受(第一步)
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler:) name:@"mynotification" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler2:) name:@"mynotification2" object:nil];
}
//自定义接收信息和处理的方法(第二步)
-(void) notificationHandler:(NSNotification *) notification{
secondField.text = [notification object];//收到消息后在UItextField中显示出来
}
//自定义接收字典信息的方法
-(void) notificationHandler2:(NSNotification *) notification2{
NSDictionary *dict = [notification2 object];
NSLog(@"receive dict :%@,forkey:%@",dict,[dict objectForKey:@"one"]);
}
注意:如果注册的notification在目标视图没有收到或名称写错,目标视图的相关方法就不会执行
[2] 一般情况上安装APK
来源: 互联网 发布时间: 2014-02-18
一般情况下安装APK
private void installNormal() {
LogUtils.log(TAG, LogUtils.getThreadName());
setStatus(State.INSTALLING);
String rootpath = Environment.getExternalStorageDirectory().getPath()
+ File.separator + Environment.DIRECTORY_DOWNLOADS + File.separator;
Uri uri = Uri.fromFile(new File(rootpath + downloadFileName));
LogUtils.log(TAG, LogUtils.getThreadName() + "uri = " + uri);
Intent intent = new Intent();
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(uri, "application/vnd.android.package-archive");
mContext.startActivity(intent);
}
[3] Objective-C 下传图片至服务端
来源: 互联网 发布时间: 2014-02-18
Objective-C 上传图片至服务端
NSURL *url = [NSURL URLWithString: urlString ];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
NSMutableData *postData = [NSMutableData dataWithContentsOfFile:imagePath];
[request setPostBodyFilePath:imagePath];
[request setRequestMethod:@"POST"];
[request startSynchronous];
最新技术文章: