*** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:] - ios

I got the above error when trying to launch my app second time. First time I got it properly. But when I try to select the tableview, I am getting the error. please help me
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellIdentifier =CELL_IDENTIFIER_STRING;
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier] autorelease];
cell.textLabel.text = [arrayname objectAtIndex:indexPath.row];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.textLabel.textColor=UIColorFromRGB(0xffffff);
return cell;
}

- (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] autorelease];
}
////// *****************************
cell.textLabel.text = [arrayname objectAtIndex:indexPath.row];
cell.textLabel.backgroundColor=[UIColor clearColor];
cell.textLabel.textColor=UIColorFromRGB(0xffffff);
return cell;
}

Related

How can I set IndentationLevel in UITableViewCell?

I am new to swift.
How can I set IndentationLevel in UITableViewCell?
I have already achieved through Objective C, but I am not able to achieve through Swift.
EDIT:
- (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.textLabel.text=[[self.menuTableAr objectAtIndex:indexPath.row] valueForKey:#"name"];
[cell setIndentationLevel:[[[self.menuTableAr objectAtIndex:indexPath.row] valueForKey:#"level"] intValue]];
return cell;
}
Thanks
Assume that valueForKey will return a NSNumber Object
Try
let level = self.menuTableAr.objectAtIndex(indexPath.row).valueForKey("level") as! NSNumber
cell.indentationLevel = Int(level.intValue)

selected UITableViewCell data is null?

Table is showing the list of countries. But when i tried to retrieve the data its returning null value. I am trying store the cell.textlabel.text into a string but worrying with null
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:#"MyCell"];
if (cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"CellIdentifier"];
}
jsonDict = [newarray objectAtIndex:indexPath.row];
cell.textLabel.text = [jsonDict objectForKey:#"countryName"];
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
NSLog(#"country is %#",cell.textLabel.text);
cell.textLabel.text=CountryString;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
jsonDict = [newarray objectAtIndex:indexPath.row];
CountryString=[jsonDict objectForKey:#"countryName"]
NSLog(#"country is %#", CountryString);
}
your cell identifier also different
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"cell"; //here mention the correct one use either `MyCell` or `CellIdentifier`
UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier: CellIdentifier];
if (cell==nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
}
jsonDict = [newarray objectAtIndex:indexPath.row];
cell.textLabel.text = [jsonDict objectForKey:#"countryName"];
return cell;
}

how to display number from 1 to array count in IOS 7?

how to display a number from 1 to array count in a table row .
am using 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];
// NSInteger WeekList=[WeekArry count];
}
NSInteger row = indexPath.row;
cell.textLabel.text=[NSString stringWithFormat:#"Week %ld",(long)row];
NSLog(#"row%ld",(long)indexPath.row);
// Configure the cell...
return cell;
}
if (row == array.count) {
cell.textLabel.text=[NSString stringWithFormat:#"Week %ld",(long)row];
}else{
cell.textLabel.text=[NSString stringWithFormat:#"Week %ld",(long)row + 1];
}

Both TableViews showing same data?

I am using two UITableView in same View. I have used prototype cell in which there are two label to show date and venue in TableView.
Here is the code what I did. Both TableViews showing same data.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableView *tableViewOne=(UITableView*)[self.view viewWithTag:5];
UITableView *tableViewtwo=(UITableView*)[self.view viewWithTag:6];
UITableViewCell *cell;
if (tableViewOne) {
NSLog(#"In Table1");
static NSString *CellIdentifier = #"cell";
cell=[tableViewOne dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel * dateLabel = (UILabel*)[cell viewWithTag:111];
dateLabel.text = [dateArrayLableInTableviewOne objectAtIndex:indexPath.row];
UILabel *venueLabel=(UILabel*)[cell viewWithTag:114];
venueLabel.text=[venueArrayLabelInTableViewOne objectAtIndex:indexPath.row];
}
else if(tableViewtwo){
NSLog(#"In Tabl2 ");
static NSString *CellIdentifier2 = #"cellTwo";
cell = [tableViewtwo dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
UILabel * dateLabelOfTableViewTwo = (UILabel*)[cell viewWithTag:211];
dateLabelOfTableViewTwo.text = [dateArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
UILabel *venueLabelOfTableViewTwo=(UILabel*)[cell viewWithTag:214];
venueLabelOfTableViewTwo.text=[venueArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
}
return cell;
}
Your if condition is incorrect. So please check like this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (tableView.tag == 5) // Change here
{
NSLog(#"In Table1");
static NSString *CellIdentifier = #"cell";
cell=[tableViewOne dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel * dateLabel = (UILabel*)[cell viewWithTag:111];
dateLabel.text = [dateArrayLableInTableviewOne objectAtIndex:indexPath.row];
UILabel *venueLabel=(UILabel*)[cell viewWithTag:114];
venueLabel.text=[venueArrayLabelInTableViewOne objectAtIndex:indexPath.row];
}
else
{
NSLog(#"In Tabl2 ");
static NSString *CellIdentifier2 = #"cellTwo";
cell = [tableViewtwo dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
UILabel * dateLabelOfTableViewTwo = (UILabel*)[cell viewWithTag:211];
dateLabelOfTableViewTwo.text = [dateArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
UILabel *venueLabelOfTableViewTwo=(UILabel*)[cell viewWithTag:214];
venueLabelOfTableViewTwo.text=[venueArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
}
return cell;
}
Do it like
if (tableView == tableViewOne){
// Your Code
}
elseif (tableView == tableViewTwo){
// Your Code
}
Your comaprison is incorrect since both table view are present, first condition get satisfied always thus same data in both tables.
Compare using UITableView object identifiers
if (tableView==first_table_view_name) {
}
else
{
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//UITableView *tableViewOne=(UITableView*)[self.view viewWithTag:5];
//UITableView *tableViewtwo=(UITableView*)[self.view viewWithTag:6];
UITableViewCell *cell;
if (tableView.tag==5) // problem is here
{
NSLog(#"In Table1");
static NSString *CellIdentifier = #"cell";
cell=[tableViewOne dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
UILabel * dateLabel = (UILabel*)[cell viewWithTag:111];
dateLabel.text = [dateArrayLableInTableviewOne objectAtIndex:indexPath.row];
UILabel *venueLabel=(UILabel*)[cell viewWithTag:114];
venueLabel.text=[venueArrayLabelInTableViewOne objectAtIndex:indexPath.row];
}
else if(tableView.tag==6){
NSLog(#"In Tabl2 ");
static NSString *CellIdentifier2 = #"cellTwo";
cell = [tableViewtwo dequeueReusableCellWithIdentifier:CellIdentifier2];
if (cell==nil) {
cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier2];
}
UILabel * dateLabelOfTableViewTwo = (UILabel*)[cell viewWithTag:211];
dateLabelOfTableViewTwo.text = [dateArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
UILabel *venueLabelOfTableViewTwo=(UILabel*)[cell viewWithTag:214];
venueLabelOfTableViewTwo.text=[venueArrayLabelInTableViewTwo objectAtIndex:indexPath.row];
}
return cell;
}

UITableViewCell.accessoryView will disappear in iOS 7

I assign some custom view to UITableViewCell.accessoryView, but if I scroll the tableView crazy, some accessoryView will disappear in iOS 7, and if I touch the cell, it's accessoryView can appear, I don't know why, because it's correct in iOS 6. This is my code, someone can help me?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [NSString stringWithFormat:#"CELL %d", (int)indexPath.row+1];
NSDictionary * dict = [_dataSource objectAtIndex:indexPath.row];
if ([dict objectForKey:#"switch"])
{
cell.accessoryView = [dict objectForKey:#"switch"];
}
else
{
cell.accessoryView = nil;
}
return cell;
}
When we use ReusableCellWithIdentifier in table view it reuse cells in table, you set cell.accessoryView = nil; it's remove accessory view for all cells in table view with same CellIdentifier try this code, it's solve your problem :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
NSDictionary * dict = [_dataSource objectAtIndex:indexPath.row];
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.accessoryView = [dict objectForKey:#"switch"];
}
cell.textLabel.text = [NSString stringWithFormat:#"CELL %d", (int)indexPath.row+1];
if ([dict objectForKey:#"switch"])
{
cell.accessoryView.hidden=NO;
}
else
{
cell.accessoryView.hidden=YES;
}
return cell;
}

Resources