jamone
jamone

Reputation: 17421

Static UITableView created in IB/Storyboarding With dynamic content?

I'm wondering if I could make a basic UITableView and statically set up everything using IB/Storyboarding in Xcode 4.2 but just one of the cells I want to display the current app version. (I'm making an about view) and I don't want to hardcode the app version because I know I'll forget to update it down the road. Is there any way to have that one cell get its data from the dataSource? I tried implementing

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

// Configure the cell...
if (indexPath.section == 0 & indexPath.row == 0) {
    cell.textLabel.text = [self appVersion];
}

return cell;
}

I've tried setting the cellIdentifier on all cells to @"Cell" as well as just setting it on the cell I care about modifying.

and only for that cell returning the app version but that wipes out the content of all the other cells.

Upvotes: 1

Views: 2307

Answers (2)

勿绮语
勿绮语

Reputation: 9320

Use different ID for the first row.

Upvotes: 0

agilityvision
agilityvision

Reputation: 7931

If you are using a Static table in Storyboards the static table is the data source.

With a Static Table in Storyboard you would put a UILabel in the cell in question. Than setup a IBOutlet property in your View Controller and hook up the label to the outlet. Then just update the label to your version number. You can hook up as many outlets as you want to different cells in a static table. Static table just means there is a fixed number of cells , you can still dynamically change the content of those fixed number of cells.

Upvotes: 5

Related Questions