Activity indicator not hiding - ios

I want to use activity indicator to show loading activity, like this:
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//Create cell
static NSString *cellIdentifier = #"cell";
MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"MyCellView" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
// Check condition, either we got objects
if (!isDataLoaded){
cell.myActivityIndicator = [[UIActivityIndicatorView alloc]
initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
cell.myActivityIndicator.center=self.view.center;
[cell.myActivityIndicator startAnimating];
[self.view addSubview:cell.myActivityIndicator];
NSLog(#"Current loading");
} else {
cell.myActivityIndicator.hidden = YES;
[cell.myActivityIndicator removeFromSuperview];
}
return cell;
}
However, its not vanish, even when i know that "else" block is executed. How to hide it?

Related

Data not displaying in UILabel

Interesting predicament: Data for 'variant' is returned successfully, and for some reason it won't display in my cell's UILabel (the UILabel just appears empty, and yes, it's 'hooked up')? Is my currencyFormatter throwing this off somehow? Should I format this line differently? Help is appreciated.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *PointsTableIdentifier = #"PointsCell";
PointsCell *cell = (PointsCell *)[tableView dequeueReusableCellWithIdentifier:PointsTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"PointsCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
BUYProduct *productsbuy = self.products[indexPath.row];
cell.productLabel.text = productsbuy.title;
BUYProduct *productDescription = self.products[indexPath.row];
cell.productDescrip.text = productDescription.htmlDescription;
BUYProduct *pointValues = self.products[indexPath.row];
BUYProductVariant *variant = pointValues.variants.firstObject;
cell.priceLabel.text = [self.currencyFormatter stringFromNumber: variant.price];
NSLog(#"%#", variant.price);
}
return cell;
}

what if when two UITableView in one ViewController and one with custom cell refrence and another is a simple

i'm trying to use two UITableView in one ViewController. one UITableView with the reference of custom cell and the other one is simple...I've written this code but it gives me error of control may reach end of non-void function...
so give me the suggestion for it...what can i do...?
thanks in advance...
here, is my code...
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==self.categoryTable)
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (nil == cell1)
{
cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell1.textLabel.text=[category objectAtIndex:indexPath.row];
cell1.textLabel.highlightedTextColor = [UIColor redColor];
return cell1;
}
else if (tableView==self.listTable)
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
RWTListCell *cell2 = (RWTListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell2 == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell2 = [nib objectAtIndex:0];
}
//NSLog(#"%ld",(long)indexxxx);
//NSLog(#"%lu",(unsigned long)imagesmarry.count );
cell2.textLabel.text=[[imagesmarry_pictitle objectAtIndex:indexxxx]objectAtIndex:indexPath.row];
//NSLog(#"%#",[imagesmarry_pictitle objectAtIndex:indexxxx]);
return cell2;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (tableView==self.categoryTable)
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (nil == cell1)
{
cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell1.textLabel.text=[category objectAtIndex:indexPath.row];
cell1.textLabel.highlightedTextColor = [UIColor redColor];
cell=cell1;
}
else if (tableView==self.listTable)
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
RWTListCell *cell2 = (RWTListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell2 == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell2 = [nib objectAtIndex:0];
}
//NSLog(#"%ld",(long)indexxxx);
//NSLog(#"%lu",(unsigned long)imagesmarry.count );
cell2.textLabel.text=[[imagesmarry_pictitle objectAtIndex:indexxxx]objectAtIndex:indexPath.row];
//NSLog(#"%#",[imagesmarry_pictitle objectAtIndex:indexxxx]);
cell=cell2;
}
return cell;
}
You can lose the second if condition
if (tableView==self.categoryTable)
{
//do stuff
return cell1;
}
else
{
//do stuff
return cell2;
}
try this, you have to init the type the cell as UITableviewViewCell and cast after. Tell me if this sample answer to your question.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
if (tableView==self.categoryTable) {
static NSString *cellIdentifier = #"Cell";
cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (nil == cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell.textLabel.text=[category objectAtIndex:indexPath.row];
cell.textLabel.highlightedTextColor = [UIColor redColor];
} else if (tableView==self.listTable) {
static NSString *simpleTableIdentifier = #"SimpleTableCell";
cell = (RWTListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = (RWTListCell *)[nib objectAtIndex:0];
}
//NSLog(#"%ld",(long)indexxxx);
//NSLog(#"%lu",(unsigned long)imagesmarry.count );
((RWTListCell *) cell).textLabel.text=[[imagesmarry_pictitle objectAtIndex:indexxxx]objectAtIndex:indexPath.row];
//NSLog(#"%#",[imagesmarry_pictitle objectAtIndex:indexxxx]);
}
return cell;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = nil;
if (tableView==self.categoryTable) {
...
...
return cell1;
}
else if (tableView==self.listTable) {
...
...
return cell2;
}
retrun cell;
}
Try this, take a dummy cell and return it at the end.
Actually your problem is not returning any cell to tableview.
I have altered your code. I just removed your else if condition
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView==self.categoryTable)
{
static NSString *cellIdentifier = #"Cell";
UITableViewCell *cell1 = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (nil == cell1)
{
cell1 = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellIdentifier];
}
cell1.textLabel.text=[category objectAtIndex:indexPath.row];
cell1.textLabel.highlightedTextColor = [UIColor redColor];
return cell1;
}
static NSString *simpleTableIdentifier = #"SimpleTableCell";
RWTListCell *cell2 = (RWTListCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell2 == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell2 = [nib objectAtIndex:0];
}
//NSLog(#"%ld",(long)indexxxx);
//NSLog(#"%lu",(unsigned long)imagesmarry.count );
cell2.textLabel.text=[[imagesmarry_pictitle objectAtIndex:indexxxx]objectAtIndex:indexPath.row];
//NSLog(#"%#",[imagesmarry_pictitle objectAtIndex:indexxxx]);
return cell2;
}
Just add return; at the last.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (condition 1) {
// statements
return cellType_1;
} else if (condition 2) {
//statements
return cellType_2;
}
return;
}
or you can also do this -
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if (condition 1) {
// statements
return cellType_1;
} else {
//statements
return cellType_2;
}
}
remove the second condition . because you must return in non void method weather your all condition is true or not.

how to show different custom cell in a table view in ios

1. in my method in write code example given below -
(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
static NSString *simpleTableIdentifier2 = #"SimpleTableCell2";
if (indexPath.row== 0) {
SimpleTableCell *cell = nil;
cell=(SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
}
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
if (indexPath.row == 1) {
SimpleTableCell2 *cell2 = nil;
cell2=(SimpleTableCell2 *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier2];
}
if (cell2 == nil)
{
NSArray *nib2 = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell2" owner:self options:nil];
cell2 = [nib2 objectAtIndex:0];
}
cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
cell.prepTimeLabel.text = #"detail";// [prepTime objectAtIndex:indexPath.row];
//cell.imageView.image = [UIImage imageNamed:#"creme_brelee.jpg"];
cell2.nameLabel.text = [tableData objectAtIndex:indexPath.row];
return cell;
}
can any one help me am i write correct code becoz it will give an error
the error is use of undeclear identifier cell and cell2
i dont understand what is this error
it gives the error after making cell2 before cell2 it works perfectly
help me
thanks
It is giving the error because you have declared it like this:
if (indexPath.row== 0) {
SimpleTableCell *cell = nil;
cell=(SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
}
and you are using the cell variable outside the local scope of this condition.
Do this:
SimpleTableCell *cell = nil;
if (indexPath.row== 0)
{
cell=(SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
}
Also make sure that you have imported the header SimpleTableCell.h.
Hope that helps!
if (indexPath.row == 1) {
SimpleTableCell2 *cell2 = nil;
cell2=(SimpleTableCell2 *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier2];
//This is ok
cell2.nameLabel.text = [tableData objectAtIndex:indexPath.row];
}
//No you cant access outside
cell2.nameLabel.text = [tableData objectAtIndex:indexPath.row];
Here, you have declared cell2 inside the if block. So you can use this variable in this scope only. When you try to access cell2 outside, you will get use of undeclared error.
Undeclared identifier means that you didn't register cell class.
You should do that in viewDidLoad:
-(void)viewDidLoad
{
[self.tableView registerClass:[SimpleTableCell class] forCellReuseIdentifier:#"SimpleTableCell"];
[self.tableView registerClass:[SimpleTableCell2 class] forCellReuseIdentifier:#"SimpleTableCell2"];
}
However, NSStringFromClass approach is better when dealing with cell identifiers:
-(void)viewDidLoad
{
[self.tableView registerClass:NSStringFromClass([SimpleTableCell class]) forCellReuseIdentifier:#"SimpleTableCell"];
[self.tableView registerClass:NSStringFromClass([SimpleTableCell2 class]) forCellReuseIdentifier:#"SimpleTableCell2"];
}
If you didn't register a cell class, dequeueReusableCellWithIdentifier can return nil, as specified in the docs:
This method dequeues an existing cell if one is available or creates a new one
using the class or nib file you previously registered. If no cell is available
for reuse and you did not register a class or nib file, this method returns nil.
Additional note: keep your view controller methods as slim as possibile.
you could try these codes:
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath (NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
static NSString *simpleTableIdentifier2 = #"SimpleTableCell2";
if (indexPath.row== 0) {
SimpleTableCell *cell = nil;
cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil){
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
cell.prepTimeLabel.text = #"detail";// [prepTime objectAtIndex:indexPath.row];
//cell.imageView.image = [UIImage imageNamed:#"creme_brelee.jpg"];
return cell;
}
SimpleTableCell2 *cell2 = nil;
if (indexPath.row == 1) {
cell2 = (SimpleTableCell2 *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier2];
if (cell2 == nil){
NSArray *nib2 = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell2" owner:self options:nil];
cell2 = [nib2 objectAtIndex:0];
}
cell2.nameLabel.text = [tableData objectAtIndex:indexPath.row];
}
return cell2;
}
if (indexPath.row== 0) {
SimpleTableCell *cell = nil;
cell=(SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
return cell;
}
if (indexPath.row == 1) {
SimpleTableCell2 *cell2 = nil;
cell2=(SimpleTableCell2 *) [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier2];
if (cell2 == nil)
{
NSArray *nib2 = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell2" owner:self options:nil];
cell2 = [nib2 objectAtIndex:0];
}
return cell2;
}
UITableViewCell *commonCell = [tableView dequeueReusableCellWithIdentifier:#"commonToALL"];
if (commonCell == nil) {
commonCell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:#"commonToALL"];
}
return commonCell;
Try This. This will create two specific cell for index 0 and 1 while two general Cells for remainder as you have 4 rows.
You'd better check you custom cell's tag in SimpleTableCell.xib
whether the tag is 0
and just one custom cell could work like:
(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = #"SimpleTableCell";
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"SimpleTableCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.nameLabel.text = [tableData objectAtIndex:indexPath.row];
cell.thumbnailImageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];
cell.prepTimeLabel.text = #"detail";// [prepTime objectAtIndex:indexPath.row];
//cell.imageView.image = [UIImage imageNamed:#"creme_brelee.jpg"];
if (indexPath.row == 1) {
[cell.thumbnailImageView.image setHidden:Yes];
[cell.prepTimeLabel.text setHidden:Yes];
}
return cell;
}

UITableView reuse cells (stop duplicating)

This is my code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"simpleTable";
profileCellViewController *cell = [self.myTable dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"simpleTable" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//loading data
...
...
...
cell.name.text = name;
cell.time.text = time;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
return cell;
}
I know the problem is in the if (cell==nil) part
but really don't know hoe I can solve this...
every time im back to this viewcontroller tab the cells duplicated

iOS: lldb EXC_BAD_ACCESS Custom Cell

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"LibraryListingCell";
InSeasonCell *cell = (InSeasonCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"InSeasonCellView" owner:self options:nil];
cell = [_cell autorelease];
_cell = nil;
}
if(_dataController!=NULL){
Product *productAtIndex = [_dataController objectInListAtIndex:indexPath.row];
// Configure the cell...
if (productAtIndex.name != nil && productAtIndex.week != nil && productAtIndex.image != nil) {
cell.name.text = productAtIndex.name;
cell.week.text = productAtIndex.week;
cell.image.image = productAtIndex.image;
}
}
return cell;
}
Message ERROR for cell.name.text cell.week.text cell.image.text. Pretty sure it is a memory management error. I have retained and released properly to the best of my knowledge. The application will crash upon launch, sometimes it loads everything fine, but when you scroll it crashes. Any help or pointers about memory management is appreciated.
Instead of this:
if (cell == nil) {
[[NSBundle mainBundle] loadNibNamed:#"InSeasonCellView" owner:self options:nil];
cell = [_cell autorelease];
_cell = nil;
}
You sent autorelease message and set it to nil, later you are trying to access that released cell.
I think it should be as:
static NSString *CellIdentifier = #"LibraryListingCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

Resources