I have the following code in my didSelectRowAtIndexPath delegate method:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
Exercise *exerciseView = [[Exercise alloc] initWithNibName:@"Exercise" bundle:nil]; //Makes new exercise object.
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSString *str = cell.textLabel.text; // Retrieves the string of the selected cell.
exerciseView.exerciseName.text = str;
NSLog(@"%@",exerciseView.exerciseName.text);
[self presentModalViewController:exerciseView animated:YES];
}
In this, I try to take the text of the selected cell, and set the IBOutlet UILabel exerciseName to that string.
My method compiles, but when I run the NSLog, which prints the textvalue of the UILabel after setting it to str, it returns null. I feel like this is a pointer problem, but can’t seem to grasp it. Can anyone clarify things?
The problem is the half-initialized view controller. Need to let it get built before you init the contents of a subview.
Exercise.h
Exercise.m
Call that new initializer from your didSelect method.
But please get that str by using the logic within cellForRowAtIndexPath, not by calling it.