I used the following code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
// cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
if (indexPath.row == 0) {
CGRect myImageRect = CGRectMake(120.0f, 5.0f, 70.0f, 55.0f);
UIImageView *myImage = [[UIImageView alloc] initWithFrame:myImageRect];
[myImage setImage:[UIImage imageNamed:@"logo.png"]];
[cell.contentView addSubview:myImage];
}
else {
int arrayIndex = [indexPath row]-1 ;
mdict = [mmenuitems objectAtIndex:arrayIndex];
[mdict retain];
cell.textLabel.text =[mdict objectForKey:@"name"];
I got correct JSON parsed message in mmenuitems,and used indexPath.row = 0 to display a logo.
But the problem is I didn’t get the last item in tableview.
Also when I scrolls the tableview the data reloads randomly and same gets repeated.
I can gusse that you need to add 1 to your number of rows method:
So your rows count will be all the objects in the
mmenuitemsarray + 1 cell for the logo.But
a better way will be to add your logo to the table view
header viewand not to the table view rows, you can do it in your view did load after the table view is loaded:It will add your logo to a view on top of the first table row and won’t mix in your table rows. I believe it will resolve your repetition problem.
Good luck