How to make uitableview load many sections at a time? - ios

i have a UITableView to show pictures ,each picture has a name;for some reason, i have to make the name as a section header,and the picture as a section row,the major code is like this:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [dataList count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
...
return view;
}
the picture is as big as 640*640;
my problem is : every time ,the picture will not load until its top shows in the screen;
i want to load many pictures at a time ,but the fact is a picture is loaded when its top shows in the screen;

Since the delegate method that asks you for a cell won't get called until a new cell is about to get into the view, you have to preload images somewhere outside the delegate method.

Related

why can't I focus on correct uitextfield in the uitableview cell (goes over navigation bar) in iOS, objective c

I'm using a TableViewController with custom TableViweCell to gather user information. inside my custom TableViweCell there are more than 5 textfields. (NOTE : I'm using tableview controller because it helps scroll above keyboard automatically when tap on uitextfield). so when I tap on first uitextfield, automatically focus on it and automatically scroll it to up(stop near the navigation bar bottom line.). then when I tap on another uitextfield it scrolls to up with passing the navigation bar.then user has to scroll down to type on it. what is the problem with this.
should I use different custom uitableview cells for each textfield
tableview .m file implementation.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
HoteluserdetailformTableViewCell *formcell = [tableView dequeueReusableCellWithIdentifier:#"hotelformcell" forIndexPath:indexPath];
return formcell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return screenSize.height;
}
Found the solution for this.if we want to use more than one text field we have to return that much of rows in number of rows in section method.
ex : if you want 5 text fields
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;
}
note : use 5 text fields inside the same custom cell does not work for this.

refresh view controller at the end of table in bottom in ios

Blockquote
How to set the position of refresh controller in iOS at the end of table.
After last data refresh
controller must be shown
Try this -
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return arrData.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
if (arrData.count==indexPath.row+1) {
//call reload method & reload tableView
}
...
}

Using UITableViewDataSource methods with static cells

First of all, do not mark this as duplicate right away. I know that using UITableViewDataSource methods with static cells is not recommended and usually results in a crash, but I want to know the behavior that leads to this.
In the IB, I have a UITableViewController with 10 different static cells in a single section. I want to be able to rearrange and separate them into multiple sections without using prototype cells, since they will never be reused. Below are my implementations for the data source methods:
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return self.indexMappings.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [(NSArray*)self.indexMappings[section] count];
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell;
NSIndexPath *mappedIndexPath = [self getMappedIndexPathForIndexPath:indexPath];
cell = [super tableView:tableView cellForRowAtIndexPath:mappedIndexPath];
return cell;
}
The problem here is, if self.indexMappings.count is greater than the number of sections in my static table, the app crashes. But if its less than or equals, the mappings work just fine. For clarification, self.indexMappings is a two dimensional NSArray*. Anyone know the reason for this behavior?
I found out that the way to do this is to also implement some of the UITableViewDataSource methods as well. When the app crashes, it can be seen from the call stack that the methods causing the trouble are methods that determine the header or footer height, or header or footer views, etc. After implementing the following methods to return some default values, the problem was solved.
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
-(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath;
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;

Cannot see cells when I have Two UITableViews in one UIViewController

First of all this is not a duplicate as I have read through very similarly titled questions but they do not give me the correct answer!
So what I have done is:
First of all create a Table View with 13 unique (contain different buttons) prototype cells where the table views content is "Dynamic Prototypes". I then created a UITableViewCell class called blurCell.
I can see the new/second UITableView but there are no cells within it?
I currently have (for the first UITableView) the code:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 25;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
...
}
But I did this because I was using a .xib for this table.
Do I need this kind of code for the new/second UITableView as I have done everything manually in the storyboard?
Please help?
In the ViewController.m (ImagesTableViewController) that contains these two tables I have the code:
#interface ImagesTableViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
Which is linked to both tables
Each tableView should be declared as its own property with the delegate/data source set to self most likely in viewDidLoad
You need to do something like this for the delegate/data source methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(tableView==firstTableView) return 25;
else if(tableView==secondTableView) return 2;
else return 15;
return 0;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
if(tableView==firstTableView) return 1;
else if(tableView==secondTableView) return 2;
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{...}

How to add submenu's in table view in ios

i don no whether this question asked or not but i still searching for an answer.Am working in tableview concept and i am creating a table view like with some set of menu's like inbox, sent,setting etc.Now what i want is i want to create sub menu's inside every menu, for example if i click inbox it should show new,replied,deleted etc like this for every main menu i want to create sub menu. Using array we can load by checking section but with out using array i want to create directly and notable one i have used custom cell i also want to show images as per the menu if it is inbox i have to show inbox image. Could any one help me??
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 8;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 8;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cellidentifier=#"ViewProfileCell";
MyHomeViewCell *cell= [[MyHomeViewCell alloc] init];
cell=(MyHomeViewCell*)[tableView dequeueReusableCellWithIdentifier:cellidentifier];
if(!cell)
{
NSArray *nibofMyHomeCell=[[NSBundle mainBundle]loadNibNamed:#"MyHomeViewCell" owner:self options:Nil];
cell=[nibofMyHomeCell objectAtIndex:0];
}
if(indexPath.section==0)
{
cell.MyHomeMenuLabel.text=#"Inbox";
}
}
Here ara a good tuts it could help you:
Expanding/Collapsing TableView Sections
Expandable UITableView
And this github awesome code here by Oliver Letterer.
You can create a UITableview which will contain cells on it as you said inbox, sent, setting etc.
After you need to create another UITableView which will contain your submenu buttons or labels like new,replied, deleted when click on inbox.
Simillarly you will do for rest of the cells in your main UITableView.
And don't get confuse on how will i identify which tableview will get called.
You will check for tableview name like below:
if(tableView==main)
{
///Code for main menu tableview.
}
else if(tableView==sub)
{
////Code for submenu tableview.
}
This you will do in all UITableView Delegate and Datasource methods:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
There are many ways you can do this. You could for example show each item as a section header and if the section header is tapped you show (or hide) all of the rows in that section. The rows being the 'sub menu' items (new, replied, deleted). Or you could use different sections for each part and how or hide the sections. Or show and hide rows. This is pretty much all controlled by changing the section and row counts.

Resources