我一直在为此工作了几天,并且无处可去。我将不胜感激任何帮助。iphone将数据添加到服务器并显示在一个表中查看
我正在创建一个应用程序,它从服务器获取数据(类似于便条列表),并将其显示在表格视图中。
当用户想要在表格视图中显示/刷新数据时,用户点击刷新按钮。然后,我打电话给我的“refreshNote”方法,它看起来是这样的:(简版)
-(IBAction)refreshNote:(id)sender{
NSString *getNoteCGI = @"http://....../get-notes.cgi";
NSURL *url = [NSURL URLWithString:getNoteCGI];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
}
当连接成功,我每个音符检索存储的信息在AppDelegate的文件我的“笔记”阵列。注意包含:
noteId (auto incremented id)
userId
timestamp
noteText
到目前为止,它工作正常。 但是,为了添加新的笔记,用户点击放置在表格视图中的“添加”按钮。通过点击“添加”按钮,应用程序将移动到显示userId和noteText文本框的视图控制器。当“发送”,在视图控制器按钮被窃听,我打电话给下面的方法:
-(IBAction)send:(id)sender{
NSString *userId = self.userIdTextField.text;
NSString *note = self.noteTextField.text;
Note *note = [[Note alloc] init];
note.userId = userId;
note.note = note;
NSString *addCGI = @"http://......../add-note.cgi";
NSURL *rul = [NSURL URLWithString:addCGI];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
addConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:YES];
if(addConnection){
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
[appDelegate.notes addObject:newNote];
}else{
return;
}
}
这种成功增加了一个新的tweet表视图,但它并没有显示noteId
和timestamp
正确,因为我只是将userId
和noteText
添加到notes
阵列。
所以我应该只是刷新表视图,只要我添加一个新的笔记到服务器?这是我唯一需要做的事情吗?我完全迷失了,不知道我是否在正确的轨道上。
太棒了!我不确定我是否错过了其他重要的作品。非常感谢。 – kabichan 2013-03-18 15:27:14