When I use dynamic prototypes, I found my label is overlapping.
"firstLabel" is the default text of the label I have inserted on storyboard and I set the text "ios" when the program run.
Following are my code.
@implementation ViewController{
NSArray* _books;
}
- (void)viewDidLoad {
_books=@[@"ios",@"android"];
self.table.dataSource=self;
self.table.delegate=self;
// Do any additional setup after loading the view, typically from a nib.
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
NSInteger row=indexPath.row;
NSString* cellID=(row%2==0?@"cell1":@"cell2");
UITableViewCell* cell=[tableView dequeueReusableCellWithIdentifier:cellID forIndexPath:indexPath];
UILabel* label=(UILabel*)[cell viewWithTag:1];
label.text=_books[row];
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return _books.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 80;
}
Thank everyone for your replies. I found when I use two cellIDs, they maybe mixed. After I set only one cellID, it gets right.
NSString* cellID=(row%2==0?@"cell1":@"cell2");
change to NSString* cellID=@"cell1";
because the firstLabel's height is equal to the cell. and the firstLabel in the above of the custom label.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.