Reputation: 65
I'm trying to populate each of my UITableViewCells with a question and each question is in an NSArray. The questions are wider than the iPhone screen can display and I'm having trouble figuring out how to display the question so it returns to the next line to display the entire question.
I originally went with a CustomCell class that inherited UITableViewCell and tried to display each question as a textView but I couldn't get my question to display at all.
My goal is to give each section of the UITableView 3 rows which would all be populated by a button for the user to answer each question.
Here is the code I have to populate my UITableView
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [survey.questions count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = @"MyCustomCell";
/*
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *que = (NSString *)[survey.questions objectAtIndex:indexPath.row];
cell.textLabel.text = que;
cell.textLabel.numberOfLines = 0;
*/
CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[CustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
NSString *que = (NSString *)[survey.questions objectAtIndex:indexPath.row];
NSLog(@"Que Value: %@\n", que);
cell.queLabel.text = que;
cell.queLabel.numberOfLines = 0;
/*
if (numberOfSectionsInTableView.indexPath.section == 1) {
NSLog(@"Button 1");
}
*/
return cell;
}
Upvotes: 0
Views: 115
Reputation: 9038
You can set the word wrap with the following:
cell.textLabel.numberOfLines = 0;
If you want to add a button to the cell in the storyboard, create a new .xib
file and lay out the cell that way.
Upvotes: 1