UITableview Reload issue iOS - iphone

some times reloadData method of UITableView is not working i.e means when i wrote like [tableView reloadData] then sometimes it is calling the datasource methods and sometimes not.
what might be the problem is, can anyone please give me the answer.
Here is my code:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
[self performSelector:#selector(changeSegmentControllerFrame) withObject:nil afterDelay:0.0001];
[m_kwikiTable reloadData];
return YES; }
else
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Please add your codes.Any way check these things in your codes.
You should set cell.accessoryView out of if (cell == nil){}
2.In - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath you can use tableView and not use tableViewDistance (may be it is nil?)
3.In - (void)viewDidLoad you should call first [super viewDidLoad]; and then make customizations.
Go through this link, this will help you to debug:
tableView reloadData not working: cellForRowAtIndexPath not called

put nslog in delegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
before returning row count to check if it is retuning 0 or any other value

Try putting a breakpoint at
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
method... because if this returns zero then it will not bother executing the next method i.e.,
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

Related

Need to enable UITextField in row of UITableView when cell is selected in iOS

I have created a custom cell that places a UITextField in each row of a UITableView. What I would like to do is enable the UITextField for a particular row (i.e. activate the cursor in that textfield), when the user presses on anywhere inside the cell.
I have the following method where I try to do this:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[_cell.textField setUserInteractionEnabled:TRUE];
}
However, this is not working. Can anyone see what I'm doing wrong?
You're on the right track placing this inside didSelectRowAtIndexPath:. However, setting user interaction enabled on the textfield just means that the user would be allowed to interact with the object if they tried. You're looking for becomeFirstResponder.
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
Try this code:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[_cell.textField becomeFirstResponder];
}
What is this _cell iVar? Are you setting it somewhere?
I think what you are trying to accomplish is this:
- (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
[cell.textField becomeFirstResponder];
}
Notice that in this way you are getting the cell for the tapped indexPath.
And also, just for information, it's a pattern in objective-C to use booleans as YES or NO, instead of true or false.

UITableview Edit/delate- cell's content goes out of screen

All,
I am using UITableview and trying to implement an edit/delete function.
When I call this line .
[tblStoreAvail setEditing:TRUE animated:TRUE];
The cell's content goes out of screen.
These functions are never called.
- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
If you are using custuomTableViewCell implement the following method with your required frame for the label:
- (void)willTransitionToState:(UITableViewCellStateMask)state
{
[super willTransitionToState:state];
if(state == UITableViewCellStateDefaultMask)
{
[self.lblLocation setFrame:CGRectMake(13,22,302,21)];
}
else if(state == UITableViewCellStateShowingDeleteConfirmationMask)
{
[self.lblLocation setFrame:CGRectMake(13,22,245,21)];
}
else if(state == UITableViewCellStateShowingEditControlMask)
{
[self.lblLocation setFrame:CGRectMake(13,22,245,21)];
}
else
{
[self.lblLocation setFrame:CGRectMake(13,22,210,21)];
}
}
if you are using default TableViewCell then make sure to set delegate for tableView and do like below :
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
yourCustomCell *cell = (yourCustomCell *)[tableView cellForRowAtIndexPath:indexPath];
[cell.lblLocation setFrame:CGRectMake(13,22,302,21)];
return YES;
}
You've got two problems going on, Taimur.
1) you need to set the "delegate" of your table to whatever object (presumably your view controller) that holds those delegate methods. You can do this programmatically or via a connection in the XIB / storyboard.
2) if you're using a custom cell, you need to adjust the font sizes down to hold all the data you want to display.
If you're not using custom UITableViewCell objects to display the data in your table, then start to use them so you can get the formatting you really want to see.

Why is the rowHeight datasource method not being called

It is my fervent dream to have a UITableView with different row sizes, determined programmatically. I have read the UITableViewDataSource documentation, and I implement these methods:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
which, we can see here:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return (CGFloat) 200.0f;
}
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* test = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:nil ];
test.textLabel.text = #"TEST";
CGRect ffframe = test.frame;
ffframe.size.height *= 200.0f;
test.frame = ffframe;
return test;
}
These are just trying to make a simple table, with one row, and a height of 200.0. I try to return the height in the delegate method, and set it explicitly. Neither works.
I try trapping the heightForRow method in the debugger, it seems to never be called.
MY table rows are always the size I set in interface builder.
I have the datasource hooked up right, otherwise it would not get the rows and textLabel right.
This is a delegate method so ensure that you have
self.tableview.delegate = self;
in viewDidLoad or else have the tableview delegate property in the xib linked up to the controller.
Careful, this method is a tableview delegate not dataSource method.

Correct operation of Table View and Table Detail View

I need a small help. In my project there is a tab bar. On one of the tab bar items there is a navigation controller, on the view there is a table view.
For TableViewController there are the usual codes:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [myData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// here the DetailViewController is activated
}
The construction of DetailViewController is similar to the TableViewController. The data related to the selected row of TableView will be the key data for the SQL query, the result of which is then stored in an array. The only difference is that I use this:
viewWillAppear: includes and SQL query, then loads the result into the array sqlQueryResult.
- (void)viewWillDisappear:(BOOL)animated {
while( [sqlQueryResult count] >0 )
[sqlQueryResult removeObjectAtIndex:0];
}
This works the very first time when the table DetailView is shown. However, if we go back to TableView and select a different row, DetailView appears but the followings will not run again (as they did already): numberOfSectionsInTableView: or, tableView:(UITableView *)tableView numberOfRowsInSection: . I read in the docs that there are methods that are called only once - however I haven't seen such remark for these ones.
How can I "reset" the TableView? Or what methods should I call to set the number of its rows/sections?
What you're looking for I believe is:
[self.tableView reloadData];
You basically need to send a 'reloadData' message to your tableView. It will then call your methods again to refresh its contents.

tableview crashed when press back button of navigation controller?

the numberOfRowsInSection returns 0 when i press navigationcontroller's back button,
but - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath is called when i put break point...application crashes ..any help please?
you should set the delegate of tableview to nil, dealloc before releasing your table view like this:
- (void)dealloc{
[myTableView setDelegate:nil];
[myTableView release];
myTableView = nil;
}
besides are you trying to reload the table in viewWillDisappear, if yes you should avoid it and find a workaround for this.
Hope this helps.
Try to make the numberOfRowsInSection method return 1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}