So, I am posting my code below.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath // I get a warning here Incomplete method implementation //
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
NSLog (#"Dobby4");
NSInteger row = [indexPath row];
cell.text = [dogArray objectAtIndex:row];
//I get a warning for the line above-- 'text' is deprecated //
return cell;
}
So,
1. I get a warning - incomplete method implementation for that function.
2. I get another warning 'text' is deprecated'
3. I tried debugging and tried to print a line "Dobby4" - and it DID NOT print.
I would appreciate some help.
I doubt it is do with this function. Probably the method before. It would be good if you put that in the code listing too.
You shouldn't be using the text property to set the text (it is as the warning says, deprecated). Use the textLabel which is a subview of cell. So that line will be cell.textLabel.text = [dogArray objectAtIndex:row];.
Since it is not printing Dobby4, either your numberOfSectionsInTableView: or tableView:numberOfRowsInSection: is returning 0. If this is not so, then you haven't connected your datasource properly.
1) The compiler could be moaning as the method implementation may not be present in your header file or vice versa?
2) the .text property of a UITableViewCell is indeed deprecated since iOS 3.0 so you will not be able to use it, seeing as you are definitely targeting a higher iOS version.
3) Perhaps linked to 1).
Hope this was of some help, keep us posted!
Related
I have integrated a searchBar in my application. And it worked fine. But after adding new elements to my tableView my searchBar does not work anymore. I get error messages in this code block:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; // Here i get: >Control reaches end of non void function<
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
}
if (searching)
{
VerwaltungInformation *searchedFormel = [copyListOfFormularies objectAtIndex:indexPath.row] ; //Here i get: >Thread 1: Program received signal "SIGABRT"<
cell.textLabel.text = searchedFormel.nameFormel;
}
else
{
NSDictionary *dictionaryCell = [listOfFormularies objectAtIndex:indexPath.section];
NSArray *arrayCell = [dictionaryCell objectForKey:#"Formel"];
VerwaltungInformation *cellValue = [arrayCell objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue.nameFormel;
}
return cell;
There seems to be a problem with the cellIdentifier - but I can not figure it out.
Thanks for any help!
The warning Control reaches end of non void function comes when you wrapped up your non void method without returning an object. To figure out your problem, right click your mouse select Structure select Re – Indent. Now you can find out the structure of your code more easily and find out what is happening.
I suspect the problem might be earlier in the source file, above the method you posted. Please try this:
Step 1:
#implementation MyClass
#synthesize ...
#if 0
// all of the code that precedes cellForRowAtIndexPath
#endif
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// and so on
Does the compiler still warn on the CellIdentifier? My guess is no (though you'll probably see all kinds of errors below, related to symbols that you hid inside #if #endif).
Step 2:
Move the #if #endif pair to wrap methods one at a time in the file, method by method, starting with the method above the one you posted, until the CellIdentifier warning reappears. When it does, you'll have found the source of the problem.
What is the alternative to autorelease in ios5? Previously the following method for table views would work:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSUInteger row = [indexPath row];
static NSString *TableIdentifier = #"TableIndentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier]autorelease];
}
cell.textLabel.text = [arrAccounts objectAtIndex:row];
return cell;
}
How ever now i get a message "ARC forbids" and "autorelease is unavailable"... what is the work around for this?
simply remove the autorelease, ARC does the work for you
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:TableIdentifier];
It's damn magic
Remove the autorelease call. AFAIK the compiler is smart enough to realize that it should be autoreleased and synthesizes the appropriate calls for you.
If you don't want to make the required changes for ARC to the current file you can disable ARC for a specific file using a new -fno-objc-arc compiler flag for that file. ARC is enabled using a new -fobjc-arc compiler flag. You can choose to use ARC on a per-file basis if it’s more convenient for you to use manual reference counting for some files. More info:
http://developer.apple.com/library/ios/#releasenotes/ObjectiveC/RN-TransitioningToARC/_index.html
When i runing my iphone UITableView based application its showing me warning
WARNING: Using legacy cell layout due
to delegate implementation of
tableView:accessoryTypeForRowWithIndexPath:
in . Please remove your
implementation of this method and set
the cell properties accessoryType
and/or editingAccessoryType to move to
the new cell layout behavior. This
method will no longer be called in a
future release.
i also follow "set the cell properties accessoryType and/or editingAccessoryType" but its again showing me same warning.
Please help me to remove this warning..thanks
Here is a related question that may have the answer that you are looking for:
table view Warning
Correct, accessoryTypeForRowWithIndexPath delegate method is deprecated. We should use UITableViewCell's accessoryType and accessoryView properties to put control on right side of Cell.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"cell"];
cell.textLabel.text = #"Cell";
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
return cell;
}
Here is an xcode project that I just did to ask this question:
http://www.mediafire.com/?z26ufsfhby62br9
Open the log and run it. You will find that it outputs display: x and create: x where x is a number 0 to 49 and corresponds to the cell of the same number. It should only output to 22 before any scrolling is performed as Apple are always boasting that their tableviews are loaded as needed.
It basically shows that tableView:willDisplayCell:forRowAtIndexPath: and tableView:cellForRowAtIndexPath: are fired for each cell pretty much as soon as the tableview appears, why is this?
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"create: %i", indexPath.row);
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell...
cell.textLabel.text = [NSString stringWithFormat:#"%i", indexPath.row];
return cell;
}
- (void) tableView:(UITableView *)tableView
willDisplayCell:(UITableViewCell *)cell
forRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(#"display: %i", indexPath.row);
}
Why are the above meothds called just after the tableView loads (and just before each cell appears)? Surely they should be called just before each cell appears only?
These are the default delegate methods.. This will be be called for each cell everytime.
You use willDisplayCell:forRowAtIndexPath: to configure things like font and text color. In the newer version of the iPhone, with certain table configurations, if you configure things like the label text color in the tableView:cellForRowAtIndexPath: method, your changes will be lost at some point before the cell is actually displayed. Here you can do things like change the label's color, adjust background highlighting, such things as these.
If your table view is reloading before it actually fully displays, that could cause the behavior you're seeing. Then the cells would get initialized, prepared for display, but then all of that would be lost (before even shown on screen) as the table is reloaded.
UITableView not scrolling smoothly...(iPhone SDK) ..!!
I have implemented UITableView DataSource and Delegate methods in an individual separate classes.(one for delegate and one for datasource) in main program i write only:
//assume that all objects are allocated
ObjTableView.dataSource=ObjDataSource;
ObjTableView.delegate = ObjDelegate;
[self.view addSubView: ObjTableView];
when i run this code , UITable view appears but when i try to scroll it, it doesn't scroll smoothly.
I have also checked that UITableViewCell doesn't redraw once the cell is initialized.
can any one tell me why this happens ? How can i solve this problem ??
From comments:
ListDataSource *ObjListDataSource = [[ListDataSource alloc]initWithArray:[[sender object] valueForKey:#"List"]];
ListDelegate *ObjListDelegate = [[ListDelegate alloc]initWithArray:[[sender object] valueForKey:#"List"]];
tblList = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, 460)];
tblList.dataSource = ObjListDataSource; tblList.delegate = ObjListDelegate;
[self.view addSubview:tblList]; [tblShopList release];
More from comments:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = [NSString stringWithFormat:#"%i",indexPath.row];
UITableViewCell *cell = (UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,320,100) reuseIdentifier:CellIdentifier] autorelease];
//custom cell code
}
return cell;
}
More Information:
I have used NSNotification which notifies to current class when parsing is complete, after receiving notification , current class method calls DataSource, Delegate methods (which is defined in a separate class file).
So UItableViewCell customization (which is in ListDataSource) and table view(in current class) both are in different classes.
A problem is
NSString *CellIdentifier = [NSString stringWithFormat:#"%i",indexPath.row];
The id needs to be the same for all cells of the same class, otherwise you never reuse them. As you can see in most examples, it is indeed a constant in most (all?) cases.
Little explaination on the reuseIdentifier: every time a cell gets out of screen, you can reuse it instead of creating a new one. To reuse it, you need a cell in queue with the same identifier as the one you pass to dequeueReusableCellWithIdentifier. The way you did, the cells are never reused, because each id is unique (they may or may not be reused in case a row reappears on screen, depending on queue size, which is not configurable AFAIK). This is why personalization of the cell should happen OUTSIDE the "cell == nil" block. Long story short, you are using the reuseIdentifier not as intendend.
I think Michele is correct, but I would also add that it looks like you are doing your cell customization where the cell gets created. What you should be doing is something more like this:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *CellIdentifier = #"CellIdentifier";
UITableViewCell *cell = (UITableViewCell)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(0,0,320,100) reuseIdentifier:CellIdentifier] autorelease];
//custom REUSABLE cell code here, e.g. text color, etc.
}
NSString *cellText = [dataArray objectAtIndex:indexPath.row]; //assuming you have a simple array for your data
cell.textLabel.text = cellText;
return cell;
}
I would also add that I'm not sure why you are able to run the app with the code you have here, since UITableViewCell cell = ... is an invalid initializer. It should be UITableViewCell *cell = ....
It would be helpful to see how you are customizing your cell, since without that it's hard to see what's happening.