Translate

顯示具有 UITableViewCell 標籤的文章。 顯示所有文章
顯示具有 UITableViewCell 標籤的文章。 顯示所有文章

2013年3月26日 星期二

Custom UITableViewCell setSelectedBackgroundView

在專案又用到客制化的select時的特效改變
上網查了一下原來不難
最簡單的方法為
cell.selectionStyle = UITableViewCellSelectionStyleGray;

但是這跟我要的顏色不同
所以呢又發現到有這樣的寫法
UIView *bgColorView = [[UIView alloc] init]; [bgColorView setBackgroundColor:[UIColor redColor]]; [cell setSelectedBackgroundView:bgColorView];
如果你的Custom UITableViewCell 使用在groupe樣板
Don't forget to import QuartzCore.
UIView *bgColorView = [[UIView alloc] init]; [bgColorView setBackgroundColor:[UIColor redColor]]; bgColorView.layer.cornerRadius = 10; [cell setSelectedBackgroundView:bgColorView]; [bgColorView release];
另外一種是我沒試過的
在Custom UITableViewCell的.m檔裡作修改
- (void)setSelected:(BOOL)selected animated:(BOOL)animated { UIImage *selectionBackground = [UIImage imageNamed:@"yellow_bar.png"]; UIImageView *iview=[[UIImageView alloc] initWithImage:selectionBackground]; self.selectedBackgroundView=iview; }

2013年3月14日 星期四

Incompatible pointer type initializing 'CustomCellView *' with an expression of type UITableViewCell

雖然我不是個完美主義者
但是看到錯誤訊息還是想要把問題解決
Incompatible pointer type initializing 'CustomCellView *' with an expression of type UItableViewCell
上網查了一下
很多都是回應關於
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;

static NSString *CellIdentifier = @"CustomCell";
CustomCellView *cell =(CustomCellView*) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

但是我的問題是卡在
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;

本來寫法為
NewsCell *cell = [tableView cellForRowAtIndexPath:indexPath];

改為
NewsCell *cell = (NewsCell*)[tableView cellForRowAtIndexPath:indexPath];
就好了