Программно добавить поля в ячейку UITableView? - PullRequest
1 голос
/ 23 февраля 2011

Я пытаюсь добавить поле в ячейку. Я пытался много раз с разными методами, но не получилось Пожалуйста, помогите!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}

tableView.rowHeight = 60;

// InitWithStyle
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];

// Get Selected Name
NSString *selectedCountry = [listOfItems objectAtIndex:indexPath.row];

// Set up the cell...
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];    
cell.text = cellValue;


NSArray *resultstwoo = [database executeQuery:@"SELECT * FROM albums WHERE name=?", selectedCountry];   
for (NSDictionary *rowtwoo in resultstwoo) {
    NSString *connectionsText = [rowtwoo valueForKey:@"connections"];
    cell.detailTextLabel.text = connectionsText;
}

// Get Selected ID
NSArray *resultsID = [database executeQuery:@"SELECT * FROM albums WHERE name=?", selectedCountry]; 
for (NSDictionary *rowID in resultsID) {
NSString *selectedIDtwo = [rowID valueForKey:@"id"];

// Get latest picture and Display
int imagesCount = 0;
NSArray *listOfItemsTwo = [database executeQuery:@"SELECT * FROM images WHERE album=? ORDER BY id DESC LIMIT 0,1", selectedIDtwo];  
for (NSDictionary *rowone in listOfItemsTwo) {
    imagesCount ++;
    NSString *getDir = @"./../Documents/";
    NSString *getID = [rowone valueForKey:@"id"];
    NSString *getFile = @"_thumbnail.jpg";
    NSString *theImagePath = [NSString stringWithFormat:@"%@%@%@",getDir, getID, getFile];
    UIImage *theImage = [UIImage imageNamed:theImagePath];

    cell.imageView.layer.masksToBounds = YES;
    cell.imageView.layer.cornerRadius = 5.0;
    cell.imageView.image = theImage;

    //cell.image = [theImage imageScaledToSize:CGSizeMake(38, 38)];

    //NSLog(@"%@", theImage);

}

// If there is no images in the album, display generic picture
if (imagesCount == 0) {
    UIImage *theImage = [UIImage imageNamed:@"noalbumimages"];
    cell.imageView.image = theImage;
    //NSLog(@"%@", theImage);
}

}

return cell;


}

Еще раз спасибо.

Ответы [ 3 ]

1 голос
/ 23 февраля 2011
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{


UITableViewCell *cell=(UITableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
if(cell)
 {
return cell.imageView.size.height+10;
}
else
{
 return 44; //Return any default size you want
 }
}

// возвращает ноль, если ячейка не видна или путь индекса находится вне диапазона

проверьте этот метод. найти то, что у вас есть cell.imageview или cell.image найдите высоту этого изображения здесь и установите здесь. это метод, который возвращает размер ячейки.

С уважением,

Шьям Пармар

0 голосов
/ 12 ноября 2013

Подробный обзор о том, как это сделать, см. В следующем вопросе.

Как добавить интервал между UITableViewCell

0 голосов
/ 16 августа 2013

Ответ Шаяма немного устарел и больше не компилируется.

Кроме того, если вы исправите это, вы, вероятно, создадите бесконечный цикл. Как упоминал Одед Регев, это не способ сделать это.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...