UITableView reloadData不适用于tap事件

时间:2015-07-24 05:37:40

标签: ios objective-c uitableview cocoa-touch reloaddata

我有一个动态创建的弹出视图,其中包含动态创建的元素: The popup UIView

在" Post"中添加了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"];
}}

4 个答案:

答案 0 :(得分:0)

您必须缺少设置桌面视图的delegatedatasource。 在.h文件中写<UITableViewDataSource,UITableViewDelegate>。 并在.xib文件中设置表格的delegatedatasource

答案 1 :(得分:0)

试试这个,

[messageObject saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) { 
     //update the table data source array with new messageObject
     //then reload the tableview by
     dispatch_async(dispatch_get_main_queue(), ^{
         [self.tableView reloadData]; 
     });
}];

答案 2 :(得分:0)

如果你使用手势,那么请尝试这个

tap.cancelsTouchesInView = NO;

可能是它的帮助

答案 3 :(得分:-1)

当您收到POST方法的响应时,请写[self.tableView reloadData];可能有效。