2015-05-18 36 views
1

當我在cellForRowAtIndexPath方法中出列可重用單元格時,我發現單元格邊界總是(320,44)。CellForRowAtIndexPath方法中的單元格邊界錯誤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier]; 
    if (!cell) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault 
               reuseIdentifier:kCellIdentifier_ActCalendarCell]; 
     cell.selectionStyle = UITableViewCellSelectionStyleNone; 
} 
    cell.textLabel.text = @"test"; 
    NSLog(@"%f,%f", cell.bounds.size.width, cell.bounds.size.height); 
    return cell; 
} 

是設計的嗎?何時何地可以獲得細胞的真實界限?

+0

什麼是你想用的界限呢? – chedabob

+0

@chedabob我想爲單元格添加頂部圓形矩形,就像[this](http://stackoverflow.com/questions/22410254/round-top-corners-of-a-uiview-and-add-border) –

回答

0
NSIndexpath *indexPath=self.tableView indexPathForSelectedRow 
CustomCell *cell = (CustomCell*)[self cellForRowAtIndexPath:indexPath]; 
CGRect cellFrameInTableView = cell.frame; 

//使用這個來獲得實際座標

CGRect cellFrameInWindow = [self convertRect:cellFrameInTableView toView:[UIApplication sharedApplication].keyWindow]; 
相關問題