【发布时间】:2015-07-24 05:37:39
【问题描述】:
UITapGestureRecognizer 添加到“发布”按钮,即UILabel。一旦点击“发布”,它就会从UITextView 获取文本并将其提交到后台服务器。之后我打电话给:
[self.tableView reloadData];
绝对没有任何反应,我尝试了很多解决方案,但似乎没有任何效果,我显然在这里遗漏了一些东西,请指教
编辑
这是tableView:cellForRowAtIndexPath:
- (CustomCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
//reuse the cell from the reuse pool
CustomCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
//if there are no cells in the reuse pool then create a new cell
if (cell == nil) {
//get the nib file from the main bundle
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
//choose our cell from the array of nibs
cell = [nib objectAtIndex:0];
}
//give the cell's message property a preferred max layout width of 300
cell.message.preferredMaxLayoutWidth = 300.0;
// Configure the cell with the data
[self configureCell:cell forRowAtIndexPath:indexPath];
return cell;}
还有configureCell:forRowAtIndexPath:
- (void)configureCell:(CustomCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([cell isKindOfClass:[CustomCell class]]) {
//get data from the messages array
NSDictionary *data = [self.messages objectAtIndex:indexPath.row];
//give the colors to the username and the venue
cell.venue.textColor = [UIColor colorWithRed:119.0/255.0 green:119.0/255.0 blue:119.0/255.0 alpha:1.0];
cell.username.textColor = [UIColor colorWithRed:51.0/255.0 green:102.0/255.0 blue:153.0/255.0 alpha:1.0];
cell.time.textColor = [UIColor blackColor];
//get the name of the venue
NSString *venue = [[self.messages objectAtIndex:indexPath.row] objectForKey:@"venue"];
//if the user didn't specify the venue
if ([venue isEqualToString:@""]) {
cell.venue.text = @"No Venue Specified"; //use the placeholder
} else {
cell.venue.text = venue; //otherwise use the venue's name
}
//post message and the username
cell.message.text = [data objectForKey:@"message"];
cell.username.text = [data objectForKey:@"username"];
}}
【问题讨论】:
-
你在后台进程完成后调用
[self.tableView reloadData];吗? -
检查webservice的响应和你的tableview数组内容
-
也许您正在后台调用服务,响应后您正在后台重新加载数据。您必须在主线程中重新加载表。
-
@Akhilrajtr 这是我用来保存在后台的 Parse sn-p,它发生在
UITapGestureRecognizer的响应中:[messageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { [self.tableView reloadData]; }]; -
@ChintaN-Maddy-Ramani 好吧,如果我异步调度到主队列它也什么都不做:/
标签: ios objective-c uitableview cocoa-touch reloaddata