I saw some applications have < something > in table view cell. If I press left or right bracket, something(text 开发者_JAVA百科or graphic) between them are changed. It is used in setting menu. How can I make that? Is there any code?
You need to make a custom tableview cell by subclassing UITableViewCell and adding two buttons to the cell view.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UIImageView *imgView;
UIImageView *imgView1;
UILabel *lblName;
if(cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
imgView = [[UIImageView alloc] initWithFrame:(5,0,20,62)];
[imgView setImage:[UIImage imageNamed:@"leftimg.png"]];
imgView.tag = 55;
[cell.contentView addSubview:imgView];
[imgView release];
lblName = [[UILabel alloc] initWithFrame:CGRectMake(30, 0, 100, 25)];
lblName.tag = 77;
[cell.contentView addSubview:lblName];
[lblName release];
imgView1 = [[UIImageView alloc] initWithFrame:(200,0,20,62)];
[imgView1 setImage:[UIImage imageNamed:@"rightimg.png"]];
imgView1.tag = 66;
[cell.contentView addSubview:imgView1];
[imgView1 release];
}
else
{
imgView = (id)[cell.contentView viewWithTag:55];
imgView1 = (id)[cell.contentView viewWithTag:66];
lblName = (id)[cell.contentView viewWithTag:77];
}
lblName.text = @"your text";
return cell;
}
精彩评论