【发布时间】:2014-09-08 07:49:11
【问题描述】:
我创建按钮来添加学生,我通过显示弹出菜单(警报视图)来处理它 然后将代码输入到名为 result (NSString) 的变量中,然后调用 web 服务从我的 web 服务中获取所需的数据
- (IBAction)add_button:(id)sender {
[self addStudent];
}
- (void) addStudent {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Add Student" message:@"Enter Connection Code" delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:@"Add", nil];
[alert setAlertViewStyle:UIAlertViewStylePlainTextInput];
[alert show];
}
-(void) alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
result = [[alertView textFieldAtIndex:0] text];
NSLog(@"the result connection code %@",result);
WebService *web = [[WebService alloc]init];
[web retriveDataWithCodeAndUrl:result Andurl:STUDENT_URL];
}
在网络服务类中 完成加载并获取所需数据后 我需要找回我的 tableview 并用新数据刷新它 我尝试了协议,但它不起作用,所以我尝试制作我的 tableview 类的实例 ,我也尝试发出通知来处理它并刷新视图 (网络服务类)
-(void) connectionDidFinishLoading :(NSURLConnection *) connection{
NSLog(@"data finish loading ");
School_TableViewController *home = [[School_TableViewController alloc]init];
[home didFinishWithData:respone];
[[self delegate]didFinishLoadingwithData:respone];
[[NSNotificationCenter defaultCenter]
postNotificationName:@"TestNotification"
object:self];
}
回到我的表格视图类来处理通知和刷新表格
- (void) receiveTestNotification:(NSNotification *) notification
{
if ([[notification name] isEqualToString:@"TestNotification"])
NSLog (@"Successfully received the test notification!");
[self.tableView reloadData];
}
但它不起作用,我需要在单例和 tableview 之间进行通信的好方法 以及刷新视图的方法
提前谢谢你
【问题讨论】:
-
因为您没有将任何新数据传递给您的表格视图。您只需使用旧数据调用 reload 方法。因此,当您获得 Web 服务的响应时,请解析它或根据您的逻辑将其简单地传递给 tableview,然后调用 reload。
-
我没有传递新数据,我只是用新数据填充我的数组,但是当它返回通知方法时它返回 nil(names array),我在通知方法中传递新数据
-
你在通知中发送“self”并且没有数据,而且我没有看到 newdata 在 receiveTestNotification 方法中填充数组的位置
标签: ios iphone xcode uitableview