autorelease alternative on ios5 - iphone

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

Related

SearchBar does not work anymore after adding new objects

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.

UITableViewController warnings - Help !

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!

why [self.tableView reloadData] does not Work?

This is the code for cellForRowAtIndexPath: method.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = #"SimpleTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) { cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row];
cell.textLabel.text = [array objectAtIndex:row];
return cell;
}
When i use [self.tableView reloadData]; nothing happening?
You need to implement at least the tableView:numberOfRowsInSection: method as part of the UITableViewDataSource protocol, and tableView:cellForRowAtIndexPath: (which you already did). You should also implement numberOfSectionsInTableView:.
Then you need to make sure that your class is actually used as a data source:
self.tableView.dataSource = self;
That needs to be either done via Interface Builder or in awakeFromNib or some other method like viewDidLoad:.
Do you check your dataSource and delegate of UITableView ? I think the dataSource is nil or something else.
Try putting a break point in cell for row and see if it is called when u call reloadData. Also pls check if the changes are already made to array from which the cells are populated and make sure the table view is connected to its datasource and delegate.

UiTable view warning delegate implementation of tableView:accessoryTypeForRowWithIndexPath:

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

MGTwitterEngine and TableView

I sorta understand better how what the MGTwitterEngine returns....I thought. But i'm still doing something wrong to get it into my table view. This is what I have in my cellforrowatindexpath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:#"Default"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:#"Default"] autorelease];
}
NSDictionary *record = [NSDictionary dictionaryWithContentsOfFile:[twitterEngine getUserTimelineFor:username since:nil count:20]];
cell.text = [record valueForKey:#"text"];
return cell;
}
What am I doing wrong? Thanks
getUserTimelineFor:since:count: does not return a list of tweets. It executes an asynchronous call that goes off and attempts to download the information. Whether or not this is successful is communicated to the object designated as the engine's delegate (and implements the MGTwitterEngineDelegateProtocol).
In other words, you need to understand the delegate pattern a bit more.
I was totally overlooking the delegate methods and what they can do. MGTwitterEngine is more powerful than I initially thought. What worked was using the did get statusRecieved method to create an array from the returned array.