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

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.

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;
}

Populating UITableView with data from NSMutableArray

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

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?

objective-C syntax beginner question

i want to use the appRecord.myName in the viewDidLoad,
when i put it there it error up that appRecord is undeclared, how to declare it?
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"pilotWay";
static NSString *PlaceholderCellIdentifier = #"PlaceholderCell";
int nodeCount = [self.entries count];
if (nodeCount == 0 && indexPath.row == 0)
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:PlaceholderCellIdentifier] autorelease];
cell.detailTextLabel.textAlignment = UITextAlignmentCenter;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
cell.detailTextLabel.text = #"load";
return cell;
}
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:CellIdentifier] autorelease];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
if (nodeCount > 0)
{
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
cell.textLabel.text = appRecord.myName;
cell.textLabel.text = appRecord.appName;
}
return cell;
}
Do you have #import "AppRecord.h" at the top of that file?
It appears that appRecord is declared (= does that). Perhaps you need to cast it, though: (AppRecord *)[self.entries objectAtIndex:indexPath.row]. Whatever you do, to check whether appRecord exists, try the following and run:
NSLog(#"appRecord: %#", appRecord);
You should get a description of the object appRecord with a memory address if it exists. Let me know if any of this helps, or if you need further explanation.