iphone code - use a custom table instead of default one
i'm using a default style table,
i want to add more rows to the table, how can i customize it?code:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
// Leave cells empty if there's no data yet
if (nodeCount > 0)
{
// Set up the cell...
ARecord *aRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = aRecord.lDate;
cell.detailTextLabel.text = aRecord.WNum;
// Only load cac开发者_如何学编程hed images; defer new downloads until scrolling ends
//(!aRecord.appIcon) - use icon
if (!aRecord.appIcon)
{
if (self.tableView.dragging == NO && self.tableView.decelerating == NO)
{
[self startIconDownload:aRecord forIndexPath:indexPath];
}
// if a download is deferred or in progress, return a placeholder image
cell.imageView.image = [UIImage imageNamed:@"Placeholder.png"];
}
else
{
cell.imageView.image = aRecord.appIcon;
}
}
return cell;
}
Not sure that I understand the question. The number of sections and rows in the table are controlled by the table view's UITableViewDataSource (in most code examples, that protocol is implemented by the view's controller, but it could be a separate object).
The code you've posted comes into play much later in the process: after the view has determined how many rows are present, total, and which are currently on-screen, and needs to render those rows. But, in general, it and the other methods of the UITableViewDelegate protocol are how you'd customize the appearance and behavior of the table. (Along with the properties of the view itself.)
The number of rows in the tableview is determined by what you return in
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
if you return 500 there, you'll have a 500 row table.
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; }
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [tblArray count]; }
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSString *CellIdentifer=[NSString stringWithFormat:@"%i",indexPath.row]; UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:CellIdentifer]; if(cell==nil){ cell=[self myCustomCell:CellIdentifer dicToSet:[tblArray objectAtIndex:indexPath.row]]; [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; } return cell; }
-(UITableViewCell*)myCustomCell:(NSString*)CellIdentifer dicToSet:(NSDictionary*)dicToSet { UITableViewCell *cell=[[[UITableViewCell alloc] initWithFrame:CGRectMake(0, 0, 320, 44) reuseIdentifier:CellIdentifer] autorelease];
UIImageView *imgV=[[UIImageView alloc] initWithFrame:CGRectMake(2, 2, 40, 40)];
[imgV setImage:[UIImage imageNamed:[dicToSet valueForKey:@"Photo"]]];
[cell addSubview:imgV];
[imgV release];
return cell;
}
精彩评论