I've buttons in the dynamic cells of my UITableViewController
. I've put them there programmatically with the code below. If I press a button now the UITableView
disappears and I get a blank screen. When I go back a ViewController and go again to the UITableViewController
all seems normal + the URLConnection
did its job. What is wrong with my code?
UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(voteButton:) forControlEvents:UIControlEventTouchDown];
button.frame = CGRectMake(276, 0, 44.0, 44.0);
[cell.contentView addSubview:button];
The method it triggers is the voteButton:
- (void) voteButton:(UIButton *) sender {
NSString *urlstring = [NSString stringWithFormat:@"http://www.someurl.com", (long)sender.tag];
NSString *webStringURl = [urlstring stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *jsonFileUrl = [NSURL URLWithString:webStringURl];
NSURLRequest *urlRequest = [[NSURLRequest alloc] initWithURL:jsonFileUrl];
[NSURLConnection connectionWithRequest:urlRequest delegate:self];
[self.tableView reloadData];
}
How can I reload the UITableView
after the button is pressed?
ANSWER
The NSURLConnection
wasn't finished before the TableView
was reloaded so it couldn't show anything. I've put the [self.tableview reloadData];
in the function with connectionDidFinishLoading
and now the button press is working.