[英]Multiple CustomCell's in Single UITableView
試圖在一個uitableview中獲取多個自定義單元格,但目前它不起作用,它只是使用第一個if語句塊來設置單元格外觀。 我該怎么辦? - 謝謝你的回復,Daniel Ran
代碼如下:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row == 0) {
//Facebook Tile//
static NSString *FacebookCellID = @"FacebookCellID";
FacebookTileCell *FacebookCell = (FacebookTileCell *)[tableView dequeueReusableCellWithIdentifier:FacebookCellID];
if (FacebookCell == nil) {
NSString *XIBStringFacebookTile;
XIBStringFacebookTile = @"FacebookTileCell";
NSArray *FacebookTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringFacebookTile owner:self options:nil];
NSUInteger FacebookInteger;
FacebookInteger = 0;
FacebookCell = [FacebookTileArray objectAtIndex:FacebookInteger];
UIView *CellSelectedStyle = [[UIView alloc] init];
UIColor *CellSelectedStyleColor = [UIColor FacebookColor];
CellSelectedStyle.backgroundColor = CellSelectedStyleColor;
[FacebookCell setBackgroundView:CellSelectedStyle];
}
return FacebookCell;
}
else if (indexPath.row == 1) {
//Twitter Tile//
static NSString *TwitterCellID = @"TwitterCellID";
TwitterTileCell *TwitterCell = (TwitterTileCell *)[tableView dequeueReusableCellWithIdentifier:TwitterCellID];
if (TwitterCell == nil) {
NSString *XIBStringTwitterTile;
XIBStringTwitterTile = @"TwitterTileCell";
NSArray *TwitterTileArray = [[NSBundle mainBundle] loadNibNamed:XIBStringTwitterTile owner:self options:nil];
NSUInteger TwitterInteger;
TwitterInteger = 0;
TwitterCell = [TwitterTileArray objectAtIndex:TwitterInteger];
UIView *CellSelectedStyle = [[UIView alloc] init];
UIColor *CellSelectedStyleColor = [UIColor TwitterColor];
CellSelectedStyle.backgroundColor = CellSelectedStyleColor;
[TwitterCell setBackgroundView:CellSelectedStyle];
}
return TwitterCell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
//refine algorithm//
return self.view.frame.size.height/NumberofTiles;
NSLog(@"Flexible Tile Height = %d", NumberofTiles);
//imbed switch case statement later on//
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//Just one section in FeedbackTableView//
return NumberofTiles;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
這是你的問題:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
你在這里說你只有一個牢房。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.