I’m developing an iPhone application with latest SDK and XCode 4.5.2.
On a ViewController I have two UITableView. Both use the same UITableViewDataSource. My question is about static NSString* CellIdentifier;.
Can I do the following?
- (UITableViewCell* )tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString* CellIdentifier;
SingletonGlobalVars* singleton = [SingletonGlobalVars sharedInstance];
if ([tableView isEqual:shopsList])
{
CellIdentifier = @"ShopCell";
}
else
{
CellIdentifier = @"ProductCell";
}
[ ... ]
}
I need to change CellIdentifier but I don’t know if I can do this with a static variable.
Your code would work, but using a static variable does not make sense in your case. Just use a local variable. Note also that you can compare the pointers to
UITableViewdirectly, it is not necessary to useisEqualhere.(I assume that
shopsListis one of the table views.)