can someone help me with text alignment to the right in my uitableview sections ?
the defult alignment is left.
if the only way is to build custom header i will appreciate for code example.
try with this
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
//create a uitextfield and set font you want in
return uitextfield ;
}
it seems working for me.
Have you tried adding
cell.textLabel.textAlignment = UITextAlignRight;
to tableView:cellForRowAtIndexPath:?
As long as you are using cell.textLabel.text, and not the deprecated cell.text to set the text of the cell, this should work.
edit:
Sorry, I didn't catch that you were trying to do this with the section headers. I think you're going to have to roll your own header views, and return them using the UITableView delegate method -(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
Could take some work to get them to look like the default ones. Here is an example of someone describing how to theme the section headers: http://iphoneinaction.manning.com/iphone_in_action/2009/07/beauti.html
try this it is suitable for right to left languages
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
UILabel *lab = [[self.tableData objectAtIndex: section] valueForKey:kSectionTitleKey];
lab.Text = #"right to left alignment text";
lab.textAlignment = UITextAlignmentRight;
return lab.text;
}
as you see in code this is the only way to align text from right to left, create a custom label, set its text property and alight the label to the right.
Related
I have been though a ton of examples that show how to do a collapsable tableview but I cant find something that works with static cells. I have a couple cells that I made in IB that I would like to collapse if the section header is clicked but I cant figure out or understand how to do it. If anyone can tell me or point me to an example that does that, I would be grateful.
Here is an example of just one of the cells I have that would need to collapse:
You can refer to this sample: (download the sample code)
http://developer.apple.com/library/ios/#samplecode/TableViewUpdates/Introduction/Intro.html
So basically what this code does is:
You create Section in your -(UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section --> Each Section has SectionHeaderView --> Which you basically will tap and expand your table view.
You will implement the two delegate methods:
-(void)sectionHeaderView:(APLSectionHeaderView*)sectionHeaderView sectionOpened:(NSInteger)sectionOpened
-(void)sectionHeaderView:(APLSectionHeaderView*)sectionHeaderView sectionClosed:(NSInteger)sectionClosed
--> This will internally call insertRowsAtIndexPaths and deleteRowsAtIndexPaths --> Which will internally call tableview:cellForRowAtIndexPath --> Now here you need to create your cell which will have address, city etc etc...
Let me know if you need more information.
I finally found a solution I was happy with thanks to this: https://github.com/xelvenone/StaticDataTableViewController
A very simple solution with the implementation:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.reloadTableViewRowAnimation = UITableViewRowAnimationMiddle;
self.deleteTableViewRowAnimation = UITableViewRowAnimationMiddle;
self.insertTableViewRowAnimation = UITableViewRowAnimationMiddle;
if (indexPath.row == 0) {
[self toggleCellVissibilityOrReload:self.cell1];
}
[self reloadDataAnimated:YES];
}
I am stuck with a tableview where cell are displayed in stack format.Any suggestion from expertise how to implement this kind of tableview.
(i.e i need to display the one cell behind another cell. On Tapping any cell, the cell should animate and shows complete contents of cell)
EDITED:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
int defaultCellHeight = 30;
if(isSelected)
defaultCellHeight = 60;
return defaultCellHeight;
}
You can create this type of TableView by giving shadow of UITableViewCell.
Here i give you to Some links that might be helpful in your case.
https://github.com/mystcolor/jtgesturebasedtableviewdemo
https://github.com/OliverLetterer/UIExpandableTableView
https://github.com/binho/TicketSaldo
Follow This is best the Site for all Controller Ever.
https://github.com/bobmccune/Core-Animation-Demos If you look for core animation,then hope this demo works for you.
I want my tableView to show 6 rows with text in it, in this case "Example." As far as I can tell, I have my numberOfSectionsInTableView: and numberOfRowsInSection: set properly. See example code below:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
// Return the number of sections.
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
return 6;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = #"Example";
return cell;
}
The problem is when you see the image below showing lines for rows that shouldn't/don't exist.
How do I get rid of the lines showing past row 6?
The generally accepted way of doing this is to add a footer view with a frame size of CGRectZero, as such:
[tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]]
What this does is tell the table that there is a footer, and so it stops displaying separator lines. However, since the footer has a CGRectZero as its frame, nothing gets displayed, and so the visual effect is that the separators simply stop.
Swift Version
The easiest method is to set the tableFooterView property:
override func viewDidLoad() {
super.viewDidLoad()
// This will remove extra separators from tableview
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
}
This is Because of Your Table-view Height. Weather you have Write
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
// Return the number of rows in the section.
return 6;
}
But its show rows According to Table-view Size. If you Dont want to show This extra Lines then Make UITableView Style Plain To Grouped.
Short and simple answer..
self.tableView.tableFooterView = [UIView new];
You could do something along the lines of:
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:7 inSection:0];
[self.mytableView cellForRowAtIndexPath:indexPath].hidden = YES;
Im sure there are some better ways but this is the first thing that came to mind.
If you're referring to the light gray lines that appear below the last row, that's simply the default way a UITableView draws the row separator.
You could try changing the Separator style in Interface Builder (see the images below) to see if one of those might be more to your liking.
You didn't say what you do want to see past the last row. If you just want to see the window background, then just embed your table view in a UIView that's just tall enough to show the number of rows you want to see. If you want to see more rows without scrolling, then you would have to adjust the size of that containing view based on the number of rows.
To programmatically remove it, use this:
[yourTableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
It's a lot easier to:
return numberOfSections + 1
return 0 rows in the final section
This keeps it simple!
Two UITableViewCell related questions:
In my custom UITableViewCell I loop through an array (of which I do not know how many objects it holds) and add a UILabel displaying some text for each object in that array.
This means I have to adjust the height of the cell so that these labels fit in. How can I do this?
When going into edit mode, I have the cells indent, however I do not want this. I have tried the following:
cell.shouldIndentWhileEditing = NO;
and
-(BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
Both sadly failed, I have I no idea why. How could I possible remedy this?
Any help is much appreciated with either of these issues, thanks.
You can specify the height for every row with the delegate method [UITableViewDelegate tableView:heightForRowAtIndexPath:].
Just change what the method returns and the reload your table.
This method actually has nothing to do with the indendation of cell content:
Asks the delegate whether the background of the specified row should be indented while the table view is in editing mode.
You can try to set indentationWidth but I never managed to make it work.
Fortunately, it's easy to change everything you want in [UITableView layoutSubviews] method.
Example:
- (void)layoutSubviews {
[super layoutSubviews];
self.contentView.frame = self.bounds;
}
You may also need to set
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
{
return UITableViewCellEditingStyleNone;
}
For the dynamic height part there are plenty of other answers and a quick google found a tutorial here
I have a tableview that is blank by default. User can add cells to it.
I want the separator lines to be clear when there are no cells, and grey when there are cells.
I am using this code:
if ([[self.fetchedResultsController fetchedObjects] count] == 0)
{
self.routineTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.routineTableView.separatorColor = [UIColor clearColor];
}
else
{
self.routineTableView.separatorColor = [UIColor grayColor];
}
The problem is, when I launch the app with a blank table, and if I add cells, the grey lines are not there there until I restart the app. But if I start with cells there, then delete them, then re-add them, the lines are there. Any suggestions?
Maybe you are missing this?
...
else
{
self.routineTableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; // or you have the previous 'None' style...
self.routineTableView.separatorColor = [UIColor grayColor];
}
EDIT :
You need this but not only this... According to Apple Documentation :
The value of this property is one of the separator-style constants described in UITableViewCell Class Reference class reference. UITableView uses this property to set the separator style on the cell returned from the delegate in tableView:cellForRowAtIndexPath:.
That means the style wont change for cells that are already loaded. Just scrolling the table to force cells to redraw should make separators appearing...
You then have to :
set it BEFORE cell is inserted
OR
reload tableView when the first cell is added
which is not easy to do with a NSFetchedResultsController, you should look into its delegate for a solution... or change direction, like hiding the tableView until you have a result maybe...
EDIT 2 : You can also simply add this :
[self.tableView reloadData];
but that's a dirty workaround that will just reload full tableView, losing most benefits of NSFetchedResultsController...
A quick fix I usually do is:
#pragma mark - UITableViewDelegate
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView respondsToSelector:#selector(setSeparatorStyle:)]) {
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
}
}
This changes the boolean flag of whether there will be a separator or not. Put this in viewDidLoad:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
And to make sure you've really made it go away, set the seperatorColor property to whatever the background color of the view and cell would be:
// If the background is white
self.tableView.separatorColor = [UIColor whiteColor];
So then even if somehow the above does not get called and the separator is still persisting - it would be the same color as what is behind it, therefore invisible.
Good luck.