I am trying to add an image next to the cell text in the 8th row. My issue is that it doesn't entering inside (indexPath.row == 9) method while I have put breakpoint I get this value from indexPath.row = {length = 2, path = 0 - 0}. So please where would be my issue?
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [data count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (!cell)
{
cell = [[[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleValue1) reuseIdentifier:#"cell"] autorelease];
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"bakiyem-cell-bg.png"]];
img.x = 10.;
img.y = -6.;
[cell.contentView addSubview:img];
[img release];
//
cell.textLabel.font = [Constants regularFontWithSize:24.];
cell.textLabel.textColor = [Constants textGrayColor];
cell.detailTextLabel.font = [Constants mediumFontWithSize:24.];
}
cell.detailTextLabel.textColor = indexPath.row == 4 ? [UIColor colorWithRed:218./255. green:0 blue:37./255. alpha:1] : [Constants textGrayColor];
//My issue
if (indexPath.row == 9) {
cell.imageView.image = [UIImage imageNamed:#"info-logo.png"];
}
//
NSDictionary *dic = [data objectAtIndex:indexPath.row];
cell.textLabel.text = [dic objectForKey:#"value1"];
cell.detailTextLabel.text = [dic objectForKey:#"value2"];
return cell;
}
It really should be
if (indexPath.row == 7) {
Because you only have one row.
If the break point is still not entering your if statement, then add some more logging around it to see what is going one.
Like how about if you try
NSLog(#"row = %i", indexPath.row);
if (indexPath.row == 7) {
NSLog(#"In if statement for row = %i", indexPath.row);
UIImage *myImage = [UIImage imageNamed:#"info-logo.png"];
NSLog(#"My image=%#",myImage);
cell.imageView.image = myImage;
}
What shows up in NSLog?
The eight row has an index of 7
You probably mean indexPath.row instead of indexPath.section
If you want to customize UITableViewCells, please use custom cells
try it with indexPath.section == 7. Or probably indexPath.row == 7 as Cem has written in the comment.
Do you have 9 rows inside 1 section, or 9 sections and in each section 1 row?
For the first case use:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1 ;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section==0)
{
return 9;
}
}
For the second case;
(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 9 ;
}
(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
Also, in cellForRowAtIndexPath method use:
In the first case: indexPath.row==9
In the second case: indexPath.section==0
You should have atleast 9 rows is data array in the following method and indexPath.row = {length = 2, path = 0 - 0} mean you are in 0th row of 0th section. If you return hard code 9 in number of rows method then it will enter in (indexPath.row == 8)
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [data count]; }
Related
I only see one cell in my TableView.
This is my code:
- (void)viewDidLoad {
[super viewDidLoad];
self.menuItems = #[#"menu,favorite,animal,spase,nature,car,minimal"];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.menuItems count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString * indetifier = #"Cell";
MFCustomCell * cell = [tableView dequeueReusableCellWithIdentifier:indetifier];
if (!cell) {
cell = [[MFCustomCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:indetifier];
}
///this work
if (indexPath.row == 0) {
cell.imageCell.image =[UIImage imageNamed:#"Menu.png"];
cell.labelCell.text = #"work";
cell.contentView.backgroundColor = [UIColor greenColor];
///this does not work
///dont see this cell indexPath.row == 1
} else if (indexPath.row == 1) {
cell.imageCell.image =[UIImage imageNamed:#"Menu.png"];
cell.labelCell.text = #"not work";
cell.contentView.backgroundColor = [UIColor blackColor];
}
NSLog(#"count =%d",[self.menuItems count]);
return cell;
}
2015-11-14 19:50:44.720 ScreenRides[13132:1185201] count =1
You are only seeing one row because there is only one object in your array.
Try:
self.menuItems = #[#"menu",#"favorite",#"animal",#"space",#"nature",#"car",#"minimal"];
Your all code is working perfect but There is small problem in your code while creating/assigning the values to an array. please check the following code and see whether you will see the 2nd Cell or not.
self.menuItems = #[#"menu",#"favorite",#"animal",#"spase",#"nature",#"car",#"minimal"];
I am in dead end. I have UITableViewCell class that is used as "Settings" tab in my application. The cells are created and counted like this:
- (void)viewDidLoad
{
[super viewDidLoad];
self.refreshControl = nil;
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.scrollEnabled = NO;
(...) Note that Title 4 is commented
NSArray* titles = #[ #"Title1", #"Title2", #"Title3"/*,#"Title4"*/];
for (int i = 0; i < titles.count; i++)
{
SettingsTableCell* cell = [[SettingsTableCell alloc] initWithFrame: CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height / titles.count)];
cell.textLabel.text = [titles objectAtIndex:i];
cell.textLabel.numberOfLines = -1;
cell.backgroundColor = i % 2 == 0 ? [Colors colorForType:kLegiaColorWhite] : [UIColor whiteColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.font = [Fonts fontWithSize: IPHONE_IPAD(18.0, 24.0)];
cell.accessoryView = i == 0 ? calendarSwitch : (i == 1 ? scheduleFilterSwitch : wifiSwitch);
[cells addObject:cell];
}
}
I think down below everything is correct
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [cells count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return self.tableView.frame.size.height / [self tableView:tableView numberOfRowsInSection:indexPath.section];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
return [cells objectAtIndex:indexPath.row];
}
Please note that the problem occurs when I uncomment fourth title in my array.
When I enter into Settings tab it's starting to loop itself (I checked in debugger) and app rather freezes than crashes. With three titles it works like a charm. Could You help me finding why?
EDIT:
After #Avi suggested, I put breakpoint on heightForRowAtIndexPath and it loops on this specific method. In debugger I have this:
After researching and reducing items in *titles array (it worked for 1 and 2 items), I noticed that every cell had it own UISwitch, and 4th one doesn't have, as it is not needed. And layout subviews couldn't complete because of this error.
So I changed the following line:
cell.accessoryView = i == 0 ? calendarSwitch : (i == 1 ? scheduleFilterSwitch : wifiSwitch);
to that one
cell.accessoryView = i == 0 ? calendarSwitch : (i == 1 ? scheduleFilterSwitch : i == 2 ? wifiSwitch : nil);
I worked!
Help You guys for help!
i am developing an app with the help of this example in my app and everything is working as required but when i expand the expended cell and scroll down app crashes when table reaches at the end. let me post all my code here.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FSParallaxTableViewCell *cell = nil;
static NSString *cellIdentifier = nil;
// init expanded cell
if ([indexPath isEqual:self.expandedIndexPath]) {
cellIdentifier = #"ExpandedCellIdentifier";
}
// init expanding cell
else {
cellIdentifier = #"Cell";
}
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[FSParallaxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.cellImageView.image = [UIImage imageNamed:#"placeholder.png"];
}
if ([[cell reuseIdentifier] isEqualToString:#"ExpandedCellIdentifier"]) {
cell.playIconBig = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cell.playIconBig.tag= indexPath.row-1;
[cell.playIconBig addTarget:self action:#selector(play:) forControlEvents:UIControlEventTouchDown];
cell.playIconBig.frame = CGRectMake(25, 5, 25, 25);
[cell.playIconBig setBackgroundImage:[UIImage imageNamed:#"play_expand.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:cell.playIconBig];
}
// set text in expanding cell
if ([[cell reuseIdentifier] isEqualToString:#"Cell"]) {
[cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:[[rssOutputData objectAtIndex:indexPath.row]xmllink]] placeholderImage:[UIImage imageNamed:#"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
cell.clipsToBounds = YES;
//[cell.contentView addSubview:arrowImg];
cell.song.text = [[rssOutputData objectAtIndex:indexPath.row]xmltitle];
cell.artist.text = [NSString stringWithFormat:#"By %#",[[rssOutputData objectAtIndex:indexPath.row]xmlsinger]];
cell.share.text = [[rssOutputData objectAtIndex:indexPath.row]xmllikes];
cell.download.text = [[rssOutputData objectAtIndex:indexPath.row]xmldownloads];
}
// set text in expanding cell
if ([[cell reuseIdentifier] isEqualToString:#"Cell"]) {
[cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:[[rssOutputData objectAtIndex:indexPath.row]xmllink]] placeholderImage:[UIImage imageNamed:#"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
cell.clipsToBounds = YES;
//[cell.contentView addSubview:arrowImg];
cell.song.text = [[rssOutputData objectAtIndex:indexPath.row]xmltitle];
cell.artist.text = [NSString stringWithFormat:#"By %#",[[rssOutputData objectAtIndex:indexPath.row]xmlsinger]];
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// take expanded cell into account when returning number of rows
if (self.expandedIndexPath) {
return [rssOutputData count] + 1;
}
return [rssOutputData count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([indexPath isEqual:self.expandedIndexPath])
{
return 40;//height for expanded
} else {
return 140;//height for normal
}
}
and here didselectrowatindexpath method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self.view addSubview:_internetConnectionIndicator];
// disable touch on expanded cell
UITableViewCell *cell = [self.theTableView cellForRowAtIndexPath:indexPath];
if ([[cell reuseIdentifier] isEqualToString:#"ExpandedCellIdentifier"]) {
return;
}
// deselect row
[tableView deselectRowAtIndexPath:indexPath
animated:NO];
// get the actual index path
indexPath = [self actualIndexPathForTappedIndexPath:indexPath];
// save the expanded cell to delete it later
NSIndexPath *theExpandedIndexPath = self.expandedIndexPath;
// same row tapped twice - get rid of the expanded cell
if ([indexPath isEqual:self.expandingIndexPath]) {
self.expandingIndexPath = nil;
self.expandedIndexPath = nil;
}
// add the expanded cell
else {
self.expandingIndexPath = indexPath;
self.expandedIndexPath = [NSIndexPath indexPathForRow:[indexPath row] + 1
inSection:[indexPath section]];
}
[tableView beginUpdates];
if (theExpandedIndexPath) {
[theTableView deleteRowsAtIndexPaths:#[theExpandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
if (self.expandedIndexPath) {
[theTableView insertRowsAtIndexPaths:#[self.expandedIndexPath]
withRowAnimation:UITableViewRowAnimationNone];
}
[tableView endUpdates];
// scroll to the expanded cell
[self.theTableView scrollToRowAtIndexPath:indexPath
atScrollPosition:UITableViewScrollPositionMiddle
animated:YES];
}
- (NSIndexPath *)actualIndexPathForTappedIndexPath:(NSIndexPath *)indexPath
{
if (self.expandedIndexPath && [indexPath row] > [self.expandedIndexPath row]) {
return [NSIndexPath indexPathForRow:[indexPath row] - 1
inSection:[indexPath section]];
}
return indexPath;
}
#pragma mark - UIScrollViewdelegate methods
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
for (FSParallaxTableViewCell *cell in self.theTableView.visibleCells) {
[self updateImageViewCellOffset:cell];
}
}
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
[self updateImageViewCellOffset:(FSParallaxTableViewCell *)cell];
}
Please help me debugging my code. Thanks here is error msg
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
try this,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FSParallaxTableViewCell *cell = nil;
static NSString *cellIdentifier = nil;
// init expanded cell
if (indexPath.row >= [rssOutputData count])
cellIdentifier = #"ExpandedCellIdentifier";
}
// init expanding cell
else {
cellIdentifier = #"Cell";
}
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier forIndexPath:indexPath];
if (cell == nil) {
cell = [[FSParallaxTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
cell.cellImageView.image = [UIImage imageNamed:#"placeholder.png"];
}
if (indexPath.row >= [rssOutputData count]){
cell.playIconBig = [UIButton buttonWithType:UIButtonTypeRoundedRect];
cell.playIconBig.tag= indexPath.row-1;
[cell.playIconBig addTarget:self action:#selector(play:) forControlEvents:UIControlEventTouchDown];
cell.playIconBig.frame = CGRectMake(25, 5, 25, 25);
[cell.playIconBig setBackgroundImage:[UIImage imageNamed:#"play_expand.png"] forState:UIControlStateNormal];
[cell.contentView addSubview:cell.playIconBig];
}else {
[cell.cellImageView sd_setImageWithURL:[NSURL URLWithString:[[rssOutputData objectAtIndex:indexPath.row]xmllink]] placeholderImage:[UIImage imageNamed:#"placeholder"] options:indexPath.row == 0 ? SDWebImageRefreshCached : 0];
cell.clipsToBounds = YES;
//[cell.contentView addSubview:arrowImg];
cell.song.text = [[rssOutputData objectAtIndex:indexPath.row]xmltitle];
cell.artist.text = [NSString stringWithFormat:#"By %#",[[rssOutputData objectAtIndex:indexPath.row]xmlsinger]];
cell.share.text = [[rssOutputData objectAtIndex:indexPath.row]xmllikes];
cell.download.text = [[rssOutputData objectAtIndex:indexPath.row]xmldownloads];
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// take expanded cell into account when returning number of rows
if (self.expandedIndexPath) {
return [rssOutputData count] + 1;
}
return [rssOutputData count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if ([indexPath isEqual:self.expandedIndexPath])
{
return 40;//height for expanded
} else {
return 140;//height for normal
}
}
I'm quite sure that the method tableView:numberOfRowsInSection: returns the wrong number, it returns the number that bigger than the data size. Please check carefully these lines of code:
if (self.expandedIndexPath) {
return [rssOutputData count] + 1;
}
Assure that the condition of the if statement is correct. There is a case that you have modified the data else where but you don't know about that.
If you are returning number of rows after adding +1 to the data source than
if (self.expandedIndexPath) {
return [rssOutputData count] + 1;
}
you should ensure that for the additional row you should not access the modal / rssOutputData should be accessed till it bounds. If in case some how the code accesses the rssOutputData for the index for which the data doesn't exist than you should be ready to see error as below
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 6 beyond bounds [0 .. 5]'
Please re manipulate your code it's somehow trying to access the array out of bounds.
I have a view that has 2 independent cells. Everything is working properly, except the numberOfRowsInSection return that must be different for each cell.
I want my cell "dummy" to only return 1 or 2.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//I need to add some code in here that will say that
//if my cell = dummy then return 1 else
//Returning table count based on number of Team Names
return _teamNames.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0 && indexPath.row == 0) {
return indexPath.row + 20 - indexPath.row;
}
if (indexPath.section == 0 && indexPath.row == 18) {
return indexPath.row + 50 - indexPath.row;
} else {
return indexPath.row + 26 - indexPath.row;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *dummycell = #"dummy";
dummytest *cellar = [tableView dequeueReusableCellWithIdentifier:dummycell
forIndexPath:indexPath];
cellar.righthere.text = #"hello";
static NSString *CellIdentifier = #"StandingsIdent";
StandingsViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier
forIndexPath:indexPath];
Any ideas? Thank you.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// I need to add some code in here that will say that if my cell = dummy then return 1 else
// You need to set this bool value in your code somewhere - where you have some sort of toggle button between - Dummycell and StandingsViewCell
if(isDummyCell)
{
return 1;
}
else
{
return _teamNames.count; // Returning table count based on number of Team Names
}
}
You can use a NSMutableDictionary as source for your Table View data (i.e. "MyData"), so you can control the behaviour of every cell directly by the data source.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
//list of elements
if (self.keys.count == 0) {
return 0;
}
NSString *key = [self.keys objectAtIndex:section];
NSArray *mySection = [MyData objectForKey:key];
return [mySection count];
}
where keys is the array that holds your sections. When you load your data, if you want an alphabetical order, you've only to do:
NSMutableArray *keyArray = [[NSMutableArray alloc] init];
[keyArray addObjectsFromArray:[[self.MyData allKeys] sortedArrayUsingSelector:#selector(compare:)]];
self.keys = keyArray;
I am trying to count my array to set as the number of rows in my table and then multiply it by 2 because I have an invisible cell in between each cell to make the cells look separated. Every time I try to build, I get this error:
Terminating app due to uncaught exception 'NSRangeException', reason:
'* -[__NSArrayM objectAtIndex:]: index 3 beyond bounds [0 .. 2]'
This is the code I am using:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [xmlParser.calls count] * 2;
}
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
static NSString *CELL_ID2 = #"SOME_STUPID_ID2";
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"texture3.png"]];
[self.tableView setSeparatorColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"texture3.png"]]];
if (indexPath.row % 2 == 1) {
UITableViewCell * cell2 = [tableView dequeueReusableCellWithIdentifier:CELL_ID2];
if (cell2 == nil) {
cell2 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CELL_ID2];
[cell2.contentView setAlpha:0];
[cell2 setUserInteractionEnabled:NO];
[cell2 setBackgroundColor:[UIColor clearColor]];
}
return cell2;
}
TableViewCell *cell = (TableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[TableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.callTypeLabel.text = currentCall.currentCallType;
cell.locationLabel.text = currentCall.location;
cell.unitsLabel.text = currentCall.units;
cell.stationLabel.text = [#"Station: " stringByAppendingString:currentCall.station];
cell.contentView.layer.backgroundColor = [UIColor whiteColor].CGColor;
cell.contentView.layer.frame = CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height);
cell.contentView.layer.borderWidth = 1.0;
cell.contentView.layer.borderColor = [UIColor blackColor].CGColor;
if ([currentCall.county isEqualToString:#"W"]) {
cell.countyImageView.image = [UIImage imageNamed:#"blue.png"];
} else {
cell.countyImageView.image = [UIImage imageNamed:#"green.png"];
}
if ([currentCall.callType isEqualToString:#"F"]) {
cell.callTypeImageView.image = [UIImage imageNamed:#"red.png"];
} else {
cell.callTypeImageView.image = [UIImage imageNamed:#"yellow.png"];
}
return cell;
}
EDIT:
Made a closer look. Just add the /2:
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row / 2];
And it's going to work.
Just noticed the same answer below from richard.
As mayuur noticed:
in - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section:
// n = [xmlParser.calls count]
// Ok, we have n*2 items (but calls has only n!):
return [xmlParser.calls count] * 2;
// calls has n items in it, but you return n*2 items
And then in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath:
// n = [xmlParser.calls count]
// give me object from calls at index (which will be in range [0; n*2 - 1],
// which could be beyond [0; n-1] which you originally have)
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:indexPath.row];
So you should remove multiply by 2 or suggest something by your own, you'll always going to get this error unless xmlParser.calls is an empty array.
The error occured as you're doing something like cell.textLabel.text = [array objectAtIndex:indexPath.row]; it over bounds it limits. However of your requirement to left invisible (blank) cells in between, you can set some if...else conditions in UITableView datasource cellForRowAtIndexPath method, that prevents limit of array. Also set proper return count for numberOfCells.
Something like, if you've 4 values in your array. So there'll be 3 invisible cells should made.
1st Cell
blank
2nd Cell
blank
3rd Cell
blank
4th Cell
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [xmlParser.calls count] + (([xmlParser.calls count]%2)+1);
}
In your cellForRowAtIndexPath method,
do condition like,
if(indexPath.row==0)
{
cell.textLabel.text = [array objectAtIndex:indexPath.row];
}
else if((indexPath.row+1)%2!=0)
{
cell.textLabel.text = [array objectAtIndex:indexPath.row];
}
else
{
NSLog(#"%d is blank cell",indexPath.row);
}
You are multiplying the array count, no big deal
return [xmlParser.calls count] * 2;
but you should then divide the indexPath.row by to 2 to get the real index of the datasource. The table assumes that you have a datasource with the size 2n, so the table will access 0 .. 2n using the indexpath.
JointCAD *currentCall = [[xmlParser calls] objectAtIndex:(indexPath.row/2)]