我不確定這是否可能。在uitableview單元內設置一個自定義視圖的代理
所以我有一個自定義單元格 - 裏面包含一個自定義的uiview。這個UIView是一個顯示條形圖的視圖。所以我想設置dataSource,以及該UIView的委託。
如果我使用該代碼:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"StatsCell";
StatsTableViewCell *cell = (StatsTableViewCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"StatsTableViewCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.barChart.dataSource = self ;
dell.barChart.delegate = self;
}
我得到一個警告:
Assigning to 'id<JBBarChartViewDelegate>' from incompatible type 'StatsViewController *const __strong'
我該怎麼辦呢?然後,如果這是可能的 - 因爲委託方法將被調用的任何單元格 - 我怎麼區分哪些被調用?
我使用JBChartView從here。
謝謝。
爲什麼不讓單元格成爲它的子委託和數據源? –
@ Lukasz'Severiaan'Grela你能舉個例子嗎?我不知道我明白你的意思。 – ghostrider
例如在'StatsTableViewCell'的'awakeFromNib'或類似的設置'self.barChart.delegate = self;' –