我一直在尋找,並沒有完全找到我的答案。iPhone - 創建自定義的UITableViewCell頂部和底部邊框
我用JSON填充動態單元格的UITableView,我試圖隱藏任何額外的單元格。我關閉了IB中的分隔符,當然所有的單元分隔符都消失了。如何在每個tableviewcell的底部和頂部添加一行,以便只有具有信息的單元顯示邊框?我已經導入了Quartz並且一直在使用CALayer,但找不到解決方案。
我在這裏發現了一個類似的問題,但唯一的答案是沒有什麼幫助。
什麼會是一個更好的,不同的方式做到這一點?
這裏是我的cellForRowAtIndexPath和我numberOfRowsInSection:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
//set equal to the information in the array
return [_jsonDataArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
//create Dictionary of data in row
NSDictionary *jsoninfo = [_jsonDataArray objectAtIndex:indexPath.row];
//get required keys from dictionary and assign to vairables
NSString *title = [jsoninfo objectForKey:@"title"];
NSString *subtitle = [jsoninfo objectForKey:@"subtitle"];
NSURL *imageURL = [NSURL URLWithString:[jsoninfo objectForKey:@"series_image_URL"]];
//download the images.
NSData *imgData = [NSData dataWithContentsOfURL:imageURL];
UIImage *img = [[UIImage alloc] initWithData:imgData];
//set boarder for custom cells... I need to have a border on the top and bottom of the cells I am creating so xcode does not autofill the empty space.
//fill in text to cells
cell.textLabel.text = title;
cell.detailTextLabel.text = subtitle;
cell.imageView.image = img;
return cell;
}
謝謝你的幫助。什麼是最好的方法來做到這一點?我希望儘可能快。 – Siriss
更好的方法是使用鏈接問題中的代碼繼承'UITableViewCell'並覆蓋'drawRect:'方法。編輯:代碼,你可以看到更多upvotes答案。 –
我認爲在優化解決方案之前,您至少應該嘗試「更簡單」的方法 - 您可能會發現它足夠快。 –