Populating UITableView with data from NSMutableArray - iphone

I want to populate my UITableView with data from my NSMutableArray but it is getting an exception.
The exception:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM isEqualToString:]: unrecognized selector sent to instance 0xa2ba880'
My cellForRowAtIndexPath:
- (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.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
cell.textLabel.text = [callDetailArray objectAtIndex:indexPath.row];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
This is the array:
Array: (
{
callId = 3;
callKeyword = CALL100;
callName = "Call to All";
callNumber = 5908;
}
)
What I want to happen is that the cells in my UITaleView will display the data in callId, callKeyword, callName and callNumber.

In you CellDetailArray Data In Dictionary so you can Get Deta From NSMutableArray like Bellow:-
- (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.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
NSMutableDictionary *d=(NSMutableDictionary*)[callDetailArray objectAtIndex:indexPath.row];
cell.textLabel.text =[d valueForKey:#"callName"];
[cell setAccessoryType: UITableViewCellAccessoryDisclosureIndicator];
return cell;
}
if you want to show all four value in to your TableCell have to Create customeCell with Four UIlable and Sate Value like:-
YourLable1.text =[d valueForKey:#"callId"];
YourLable2.text =[d valueForKey:#"callKeyword"];
YourLable3.text =[d valueForKey:#"callName"];
YourLable4.text =[d valueForKey:#"callNumber"];

you use below code
cell.textLabel.text = [[callDetailArray objectAtIndex:indexPath.row]objectForKey:#"callName" ];
You are trying access dictionary instead of string. callDetailArray conatins dictionary data. inside the dictionary only strings are available so you must need to access it by using objectForKey

Related

Reusable cell in UITableView

I'm using a UITableView and a custom cell with a checkbox.
I have more than 1 section. When a check a checkbox in the first section, for example the cell with row = 0 and section = 0, I save the data and it works. But the cell in the row = 0 and section = 1 is also checked! How can I make the difference between those sections ?
Thank you so much!
Following sample code will help you for your situation.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
CustomCell *cell = (CustomCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = (CustomCell *) [[[NSBundle mainBundle] loadNibNamed:#"CustomCell" owner:self options:nil] objectAtIndex:0];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.checkBox = [self fillCheckBoxStatus:indexPath];//This method will say about check box whether going to SET or NOTSET.
//...
return cell;
}
use dequeueReusableCellWithIdentifier to nil like bellow...
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:nil];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil] autorelease];
////you another code..
}
return cell;
}

Data not showing in iphone tableView

I am getting data from json. It is working OK but the problem is that data is not showing in tableView.
I have checked the values that I assign to cell using NSLog but cell is not displaying any data.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
int count = [surveyList count];
NSLog(#"These are rows %d",count);
return [surveyList count];
}
- (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];
}
ObjectData *data = [surveyList objectAtIndex:indexPath.row];
NSString *testingClient = data.survey_title;
NSLog(testingClient);
NSString *cellText = testingClient;
return cell;
}
Are you not missing this?
[[cell textLabel] setText:testingClient];
You aren't assigning any text to the cell without it.
You should assign that text to label of cell.
cell.textLabel.text = testingClient;

Evaluate each row of UITableView separately iPhone

I want to show a picture if each row starts with a certain character, let's say "&" in the below example. The code below seems to only work if the first row doesn't start with '&'. If the first row has '&' all of the rows will have the picture. What's wrong?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
}
if ([[[array objectAtIndex:(indexPath.row)] substringToIndex:1] isEqualToString:#"&"])
{
cell.textLabel.text = [array objectAtIndex:(indexPath.row)];
cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1];
cell.imageView.image = [UIImage imageNamed:#"picture.png"];
return cell;
}
else
{
cell.textLabel.text = [array objectAtIndex:(indexPath.row)];
cell.detailTextLabel.text = [array objectAtIndex:(indexPath.row)+1];
return cell;
}
}
Since the first cell may be reused later on, you have to "reset" its state on every call of cellForRowAtIndexPath. Try adding cell.imageView.image = nil after cell.detailTextLabel.text in the else block.

Data is mismanaged when I scroll the UITableView

I am using following code,in cellForRowAtIndexPath:(NSIndexPath *)indexPath method
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if(currentRow >=[finalArray count]) return cell;
// Configure the cell.
for(int ii=0;ii<[keys count];ii++){
NSString *no22=[dict objectForKey:[keys objectAtIndex:ii]];
no=[NSString stringWithFormat:#"%# %"[keys objectAtIndex:ii],]
}// end of the for loop
if(searching)
cell.text = [copyListOfItems objectAtIndex:indexPath.row];
else {
cell.text=[finalArray objectAtIndex:currentRow];
currentRow=currentRow+1;
}
return cell;
}
I am getting strange behavior when I scroll the table data is completely mismanaged,please any suggestion.
Is because you are reusing cells. You can reuse more type of cells.
And why you are doing if(currentRow >=[finalArray count]) return cell; this?

I got Error while using UITableView as 'setText:' is deprecated

I got Error while using UITableView as 'setText:' is deprecated in line cell.text=cellvalue
Please anyone can how to fix this?
- (UITableViewCell *)tableView:(UITableView *)atable cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [atable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
NSString *cellValue = [listOfItems objectAtIndex:indexPath.row];
cell.text = cellValue; //Error 'setText:' is deprecated
return cell;
}
cell.textLabel.text = #"Value"
Because Apple added the Subtitle style to the table view cells, you need to use:
[cell.textLabel setText:#"String"];
instead.