UIButton grouped Buttons - ios

I'm trying to create a button set up exactly like this:
How would I do this? Can someone show me the code? Is there a way to "Group" UIButtons like this?

You'll want to use a UITableViewController with the sections set to be UITableViewStyleGrouped.
Each of the groups is a section, so you'll want to return how many sections you have with - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView.
For every section, you want to specify how many rows there are with - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section.
You'll want to customize each cell with - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath (which, by the way, tells you which section's particular row you're modifying in the indexPath variable).
Finally, you'll want to handle the row click in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath, using the pattern XCode provides for you:
[self.navigationController pushViewController:detailViewController animated:YES];
[detailViewController release];
Hope this helps!

That's a one-group UITableView with two rows (cells). The table style is UITableViewStyleGrouped. I'd recommend responding to selection of the cell using the delegate's –tableView:didSelectRowAtIndexPath: method as opposed to using UIButtons within the cell -- much nicer visual effect.

You can't group uibuttons like that. You can achieve this look-and-feel several ways, the most elegant is to use the grouped style uitableview.
However if you would want your buttons only to look like this, but not exactly like this, then you could also specify images for you buttons. Uglier way to do it, however much simpler ...

Related

Should I use a tableView for this

So I'm currently working on a project at work and wanted to get some feedback on how I would accomplish this. One of the mobile developers suggested I use a dynamic tableView, but it sounded kind of complicated for what I needed to accomplish. I just created UIButtons and UILabels, but felt that was rather cheesy. What do you all think? See image below
You can use UICollectionview or UITableview but
When using UICollectionview, you don't need to set buttons with tags or other things by getting selected items values. You can simply get -(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath and in UITableViewDelegate:
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
You get the selected row instead of the item, so for creating a grid or modified items, using UICollectionview is best. Here if you need rows only you can also use UITableview.

Assign different buttons, with different behaviours for different columns

In my project I've got UITableView.
I need to assign different buttons, with different behaviours for different columns.
Question:
Where is the correct way to set different behaviours & actions for buttons? Is it in (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath?
How is the correct way to assign different buttons with different behaviours to different columns? I am thinking about [_buttonArray objectAtIndex:indexPath.section]; is it the right way?
Example: Column 1 - Button A -> after button A pressed change button.title and size and do X.
You should use the below method for button behaviors if you want the user to be able to hit the entire cell and have the button action fire. If not, you should use an action delegate in your custom cell class. Let me know if you need help setting up the protocols file and or delegate method.
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

How to create a view for settings of my iPhone apps in Xcode storyboard

I am new in iOS programming and I would like to create I view for the settings of my app that looks like iPhone's one (like in the picture). Some of rows will call other views when taped and other will not.
What is the best way to do that? I thought about TableView with prototype cells, but is there a best way to do it? or a best-practice for what I want to do? Or maybe a tutorial online?
The fast way in Interface Builder:
Use a UITableViewController, make it STATIC and use the GROUPED style (all in IB).
You can setup the cells to show disclosure indicators (or not) in IB also.
You can segue directly from the rows or the UITableViewController to where you want to go.
If you segue from the UITableViewController, implement the "didSelectRowForIndexPath" method and call "performSegueWithIdentifier" accordingly.
A structure like this is best by UITableView.
First you select how many sections you want, and customize each section with a data structure that you have to be filled with (Probably an array.)
Then you fill up each rows inside
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method, and call your value from the array/dictionary that you have.
for going to a next view when clicked upon
Use the method
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
Hope this helps
The best way to do that is using static UITableViewCell.
See UITableView Programming.
The optimal solution here is undoubtedly UITableView. This is because firstly, you have the need to display a list of options that would have external links to other pages and UITableView is designed and used for this purpose.
In an addition to that, if you want, you can also expand and collapse the rows of your parent TableView into a Child TableView i.e a UITableView as a subview of its parent UITableView.
Put up a UITableView and populate it with UITableViewCell. That will be just fine with the requirement you have.
Hope this helps.

iOS - How to display the same table view after selecting an item

My iOS app is current transferring control to a detail view when an item in a UITableView is selected. This ia a quiz program, and I'd like to change the app so that it just redisplays the same table view with the correct answer highlighted when a row is selected. What's a good approach for doing this?
Is not clear to me if you know why the detail view is appearing. So I'll explain just in case. If you are giving control to a detail view is because somewhere in your code you are pushing that detail view. It depends on what kind of UITableViewCell you are using. If you are using one of the defaults styles, your detail view is probably been pushed in either:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
or
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath
If you are using a custom cell, then you need to look for the method in charge of pushing
that detail view.
I think a good approach would be to:
Remove that pushing wherever it is.
Not to use an `UITableViewCellAccessoryType, if you are using one.
Do something similar to the following on your tableView:didSelectRowAtIndexPath:
Find the row for the right answer in your model array, according to tapped cell.
Use that row number to generate an NSIndexPath.
Use that NSIndexPath to find the correct cell with cellForRowAtIndexPath:
Call setSelected:animated: on that cell to highlight it.
NOTE: If your quiz has more answers than the amount of UITableViewCells that fit in the screen you should scroll your UITableView to the right answer for better UX.

From UITableView to custom view

I have made a UITabelView that works nice, but when i now press a link I would like it to go to a new View, which should be different depending on the link choosen. How can i do that? If there is a nice tutorial it whould be nice.
Thanks for the help.
Implement UITableViewDelegate's method - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath and there display a picture.

Resources