I am trying to disable part of the UITableView cell. Please see image below.
This white part is a view in my cell. I don't know how to disable it, so that when user taps it nothing will happen. Maybe some king of mask?
Moving this out of the comments section. If you want padding between your cells what you should do is make each row its own section and use the delegate method
- (CGFloat)tableView:(UITableView *)tableView
heightForFooterInSection:(NSInteger)section
However, this method will not be called if your tableview is the default style. So, set your tableview style to UITableViewStyleGrouped
Then you have to implement the delegate methods so that you return a height for the footer and make sure that each row gets its own section:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
//Return however many rows you have specifically or the count of the datasource
return [array count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
CGFloat myHeight = 50.0 //your height here
return myHeight;
}
Implementing these three delegate methods like this should add a nice transparent padding between your cells.
Try this simple approach.Place a button on top of custom table view cell to mask the area which you want to be un-clickable. This acts as a mask on top of tableview cell which stops calling row did select delegate method. If you want to add any action for button click event add a method to button by passing row index.
Related
I have to set spacing between each tableview cell say of 36 pts .I am using tableview rather than custom cell for creating the cell?
You can do this by having number of sections equal to number of items to display. Each section will contain only one row. You will then return transparent header for every section which will give illusion of cell spacing.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return <Your items count>;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return cellSpacingHeight;
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView * headerView = [UIView new];
[headerView setBackgroundColor:[UIColor clearColor]];
return headerView;
}
A table view isn't like a collection view with a complex and capable layout specification, you can't specify arbitrary layouts and spacings.
So, use a collection view, or, if you want to continue with a table view, use a custom cell and add an empty section into each cell. Set the height of your cells to an appropriate value.
In my TableView i load cells based on a xib file. The cell has a imageView in the background. How to change the image when user holds finger on a row? I dont meen didSelectRowAtIndexPath, cause it means the user tapped the row.
Implement the - (void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated method on your cell subclass and change the image there based on the value of the highlighted parameter.
Hope this help
- (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath{
// update your image here
return YES;
}
I've looked through lots of examples of how to hide a static UITableViewCell by overridding heightForRowAtIndexPath, and while I've now got it working it just seems so cumbersome that I'd like to see if I'm doing something wrong.
I have a UITableViewController with a table view that has about 8 rows. This screen in my app shows a single object, so for example one row is description, one is an image, one holds a map view, etc. All of the rows are static.
In some cases, some of the objects that are shown don't have a map, so I want to hide the row that holds the mapview. Since it's a static row, I was thinking that by having an outlet property for that row (e.g. #property (weak, nonatomic) IBOutlet UITableViewCell *mapViewRow;), then I could somehow set that row's height to 0 or hide that row in viewDidLoad or viewWillAppear. However, it seems like the only way to do this is to override the heightForRowAtIndexPath method, which is kind of annoying because then I need to hardcode the index of the map row in my code, e.g.
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 6 && self.displayItem.shouldHideMap) {
return 0;
}
return [super tableView:tableView heightForRowAtIndexPath:indexPath];
}
Of course, not a big deal, but just the whole way of sizing static rows in a tableview seems like it defeats the point of setting them up in the storyboard in the first place.
EDIT - rationale behind my answer
To change the height of a row you must reload either the whole table or a subset containing that row. B/c it's a bit odd to have a row in the table w/ zero height, I prefer modifying your data source such that the row doesn't exist in the table.
There are a number of ways to do that. You could build an array from your displayItem where each row in the array corresponds to a row in the table w/ appropriate data. You would rebuild this array and then call [tableView reloadData]. My original answer would also eliminate the unwanted row by treating each data element as a section with 0 or 1 rows.
ORIGINAL ANSWER
Is your tableview a plain or grouped style? If it's a plain style, you could treat each row as a section with either 0 or 1 rows in it. In your tableView dataSource and delegate methods you would use the section index to identify the data within self.displayItem that you care about for that section.
Your code would be something like:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 8; // max number of possible rows in table
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSInteger rows = 1;
// set self.mapSectionIndex during initialization or hard code it
if (section == self.mapSectionIndex && self.displayItem.shouldHideMap) {
rows = 0;
}
return rows;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:indexPath
{
return 60.0f; // whatever you want the height to be
}
// also modify tableView:cellForRowAtIndexPath: and any other tableView delegate and dataSource methods appropriately
you can override heightForRowAtIndexPath and just write in it return UITableViewAutomaticDimension; this will make cell calculate the height automatically as UILabel height is >= . it worked for me.
To specify cell heights of a table view we use the delegate method,
- (CGFloat) tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section
However this method asks cell height of every row, what can I do if I want some of them to be defaults?
For cell height we may return UITableView#rowHeight for those default rows inside the delegate method, but I also want some (not all) of the section headers/cell to be customized.
But I am not able to get the defaults from the table view, especially for grouped style table view, anyone has a solution?
Thanks!
EDIT: I'm sorry for not making it very clear. In fact, cell height is not the only one that I want to partially customize, but also something else like section header (there may be more, like delete button style, etc.).
Is there solution without mimicking default behavior?
if you don't want default behavior in all cases, you'll still have to mimic default behavior in the non-specialized cases.
for headers, you will still have to implement
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
and therein, you will have to answer the default height for those headers you do not wish to change, and the specialized header height for those you do want to change.
similarly, in
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath*);
you will still have to mimic default behavior for those cells you do not wish to change.
you could accomplish all of this with storyboard if you want: create specialized cells with unique identifiers for each, and then return the cell heights that go with them. if you take this route, then you may be able to get away with just using dequeueReuaableCellWithIdentifier and using the height value for that identifier. just use a unique cell identifier with a height that's appropriate for each cell you're thinking of.
The default height of cell is 44 .. so you can return it when your condition is not satisfied ..
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (YOUR_SPECIFIC_CONDITION) {
return 180.0;
}
return 44.0;
}
May this will help you..
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0 && indexPath.section==0)
{
return 180.0;
}
else
{
return 44.0;
}
}
I need to do something like this :
.
Is it a UITableView? Or how should I do this? Any idea is welcome.
Code:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
if (indexPath.row == 0) return cell1;
} else if (indexPath.section == 1) {
if (indexPath.row == 0) return cell2;
} else if (indexPath.section == 2) {
if (indexPath.row == 0) return cell3;
}
}
Most likely its a UITableView. May be its not (it can be a UIScrollView with views added like sections in a table view).
But if you want to create something like in the image, I'd suggest you to use UITableView with customized cells. Because implementing table view, in this case, is simpler as you have to just concern about the delegate and the dateSource of the table view, rather than worrying about aligning the views in order.
Use sectioned table view with the translucent, gray-bordered, black-background-view as the backgroundView of the cells. Add the labels and arrow as the subviews of cell. You can add arrow as the accessoryView but that would become vertically centered, but in the image the arrow is displayed slightly on top of the cell.
There should be only one cell in each section.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 1;
}
There can be any number of sections (3 here).
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 3; // Can be any number
}
Yes, that's most likely a styled table view. See this guide or this nice tutorial.
why you worry about this one? Its simple man.... its nothing ,if you have hands over UITableView. Yeah, You must know about :
1: Set background image on view,exact as table size.
2: Set table view onto them and make background transparent.
3: Make customize table cell and add to table' row.
Thats it.....enjoy this work..its a creativity.
And you can do it guy....
I cannot tell exactly what is used from the picture, however I suggest using the UITableView especially if you have variable data coming from a structured object.
Some tutorials which I found very useful are the following:
Creating customized UITableViewCell from XIB
http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder/
UIViewTable anti-patterns - A very good MVC pattern to build UIViewTable
http://www.slideshare.net/nullobject/uitableviewcontroller-antipatterns
And of course Apple's docs:
http:/developer.apple.com/library/ios/#DOCUMENTATION/UserExperience/Conceptual/TableView_iPhone/TableViewCells/TableViewCells.html
One important fact to remember is that you should always reuse cached table cells through the datasource method tableView:didSelectRowAtIndexPath:
Note: Since you want lots of transparencies there might be some performance issue especially on older devices.
Hope this helps and goodluck with your project.
There is not need to its scrollview or tableview... both are perform same..
Just change the Background Color of Tableview as clear color.....
check this code...
put this line to viewDidLoad :
[tableView setBackgroundColor:[UIColor clearColor]];
and
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
..... // Your label buttons etc........
......
......
.....
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell setClipsToBounds:YES];
[[cell layer] setBorderColor:[[UIColor blackColor] CGColor]];
[[cell layer] setCornerRadius:10];
}
You can do this using tableView in
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
//here place return your array contents
}
We can accomplish the similar as shown in image above by Table View and scroll view both.If you don't want to use table view then you can take a scroll view or a simple view and can add several buttons along with the image in background with different frames.It means button background will have the same image.then you can use different labels to show all the texts in different labels according to the requirement.
OR
you can use table view.For this you need to return number of sections 3(in this image) in the delegate method - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView.and then everything as the default tableview style.And then change the cell style to detailed.
yes this is a tableView with custom UITableViewCell.you can do that by creating a empty xib file and then add a UITableViewCell and do your customizing ...then in cellForRowAtIndexPath method use:
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:edentifier];
if (cell == nil) {
cell = [[[NSBundle mainBundle]loadNibNamed:#"yourCellName" owner:self options:nil]objectAtIndex:0];
this is from my application.
Yes, it is a groupedtableview with clearcolor as backgroundcolor. Cell background color also needs to be changed to clearcolor.
I suggest using div or list, don't use table, its very hard to control if the contents are too long.