简体   繁体   中英

UITableView reloadData doesn't work on tap event

I have a dynamically made popup view with dynamically created elements in it: 弹出的UIView

There is a UITapGestureRecognizer added to the "Post" button which is a UILabel . Once the "Post" is tapped it takes text from the UITextView and submits it to the server in background. After that I am calling:

[self.tableView reloadData];

And absolutely nothing happens, I tried many solutions but nothing seems to work, I am obviously missing something here, please advise

EDIT Here is the 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;}

And the 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"];
}}

you must be missing to set delegate and datasource of your tableview. In your .h file write <UITableViewDataSource,UITableViewDelegate> . and in your .xib file set delegate and datasource of your table.

try this,

[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]; 
     });
}];

If you use gesture so plz try this

tap.cancelsTouchesInView = NO;

May be its help you

When you are getting the response of your POST method, write [self.tableView reloadData]; May be it works.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM