clang-formatter: Prevent new line in function declaration - ios

In Objective-C how to prevent new lines here:
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
to see this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
Tried this, but apparently not works with Objective-C:
AllowAllParametersOfDeclarationOnNextLine: false

Related

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;

NumberOfRowsInSection return issue

I am populating my UITableView with data from an RSS feed however I don't want to return all the values. how do you set the number of return values in the method below ?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return itemsToDisplay.count;
}
The method tableView:numberOfRowsInSection: is a callback, this is where you specify the number of rows to display.
Trivial answer:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return MIN(itemsToDisplay.count, 10);
}
It is necessary to insure that the returned count is no greater than the number of items in itemsToDisplay.
This will cause a maximum of the first 10 to be displayed. Is there more to the question?
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 10;
}
u can just pass any number
int returnedvalue = 5;
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return returnedvalue;
}

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
{...}

Warning trying to call BOOL method from another method

I am following an iOS tutorial and my code is supposed to be correct, but I am getting an error which is not shown at the original tutorial code.
These are the concerning methods:
-(BOOL)tableview:(UITableView *)tableView canCollapseSection:(NSInteger)section {
if (section >0) return YES;
return NO;
}
And here the piece of code supposed to be correct, but throws an error:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (tableView == self.searchDisplayController.searchResultsTableView)
{
return [self.searchResults count];
}
else {
if ([self tableView:tableView canCollapseSection:section])
{
if ([expandedSections containsIndex:section])
{
.../...
The error is shown at line
if ([self tableView:tableView canCollapseSection:section])
And this is the error message:
No visible #interface for 'ToDoItemsTableViewController' declares the selector 'tableView:canCollapseSection:'
Is there any visible error in the code?...
in your method you are calling tableView but it should be tableview. small 'V'
- (BOOL)tableView:(UITableView *)tableView canCollapseSection:(NSInteger)section
tableView : V should be capital, please check after -(BOOL):tableview part
Declare
-(BOOL)tableview:(UITableView *)tableView canCollapseSection:(NSInteger)section
in your .h file.
Also make sure that, you typed it correctly (any spelling mistake can also cause the issue).
You just need to declare your method
-(BOOL)tableview:(UITableView *)tableView canCollapseSection:(NSInteger)section
in yourViewController.h file.

Resources