Yongzhi
Yongzhi

Reputation: 1070

Table-view rows

Hey guys when I show talbeview there are a lot of empty rows... How can I make the number of rows shown exactly equal to [NSARRAY COUNT]

I am sure

- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

return the right number of rows that it should show

Upvotes: 1

Views: 186

Answers (3)

Vikas S Singh
Vikas S Singh

Reputation: 1766

You've got the right place and really have the answer already. Here it is in code: try it may be helped....

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return totalRows; } totalRows= (you want so no. of rows )

and

  • (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    NSString *CellIdentifier = [NSString stringWithFormat:@"%i %i",indexPath.row,indexPath.section]; UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; cell.accessoryType = UITableViewCellAccessoryNone; cell.accessoryType = UITableViewCellAccessoryNone; cell.highlighted = YES }

Upvotes: 0

TomSwift
TomSwift

Reputation: 39512

Set the table footerView to a view that doesn't render anything (but not nil).

tableView.tableFooterView = [[[UIView allocate] init] autorelease];

Upvotes: 2

Matthew Frederick
Matthew Frederick

Reputation: 22305

You've got the right place and really have the answer already. Here it is in code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [yourDataArrayName count];
}

Substitute the actual name of your table for tableView and the actual name of your array for yourDataArrayName, obviously.

Upvotes: 0

Related Questions