how to add rss image on UITableViewCell - ios

I am using the following code to load the RSS feed. May I know how can i add a small image from the RSS to the left hand side of the UITableViewCell? Many Thanks
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [stories count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier];
}
// Set up the cell
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
[cell setText:[[stories objectAtIndex: storyIndex] objectForKey: #"title"]];
cell.textLabel.font = [UIFont fontWithName:#"Heiti TC Light" size:16.0];
cell.textColor=[UIColor blackColor];//according to you.
cell.textLabel.numberOfLines = 3;
cell.backgroundColor = [UIColor clearColor];
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"white.jpg"]];
self.tableView.backgroundColor = [UIColor clearColor];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Navigation logic
int storyIndex = [indexPath indexAtPosition: [indexPath length] - 1];
NSString * storyLink = [[stories objectAtIndex: storyIndex] objectForKey: #"link"];
// clean up the link - get rid of spaces, returns, and tabs...
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#"\n" withString:#""];
storyLink = [storyLink stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"link: %#", storyLink);
// open in Safari
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:storyLink]];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if ([stories count] == 0) {
NSString * path = #"http://www.medworm.com/rss/medicalfeeds/source/Nature.xml";
[self parseXMLFileAtURL:path];
}
cellSize = CGSizeMake([newsTable bounds].size.width, 60);
}

I hope this will be helpful.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *MyIdentifier = #"MyIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:MyIdentifier];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(12, 5, 158/2, 99/2) ];
//SDWebImage Extension
[imgView setImageWithURL:[NSURL URLWithString:#"http://www.yoururl.com/yourimage.jpg"] placeholderImage:[UIImage imageNamed:#"placeholder.png"]];
[self.contentView addSubview:imgView];
}
return cell;
}

Related

Not inserting values probably in dynamically UITableView

i'm trying to create a dynamically fixtures which automatic updates using an API. The problem is it does connect the right sections with the right fixtures and the fixtures seem to duplicate in the different sections. Why is it not connecting the section date with the fixtures?
First i have an fixture array which contain all the fixtures.
[fixtures addObject:[[NSMutableDictionary alloc] initWithObjectsAndKeys:date,#"date", time, #"time", competition_id,#"competition_id", home, #"home", away, #"away", nil]];
Then i have an array with contain all the dates with no duplicates ordered by date called reversedArray:
NSSortDescriptor *descriptor = [[NSSortDescriptor alloc] initWithKey:#"self" ascending:NO];
NSArray *descriptors = [NSArray arrayWithObject: descriptor];
NSArray *reverseOrder = [dateArray sortedArrayUsingDescriptors:descriptors];
reversedArray = [[reverseOrder reverseObjectEnumerator] allObjects];
Then i have my view where i look
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 22)];
/* Create custom view to display section header... */
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, tableView.frame.size.width, 22)];
[label setFont:[UIFont boldSystemFontOfSize:14]];
[label setTextColor:[UIColor whiteColor]];
NSString *dateString = [NSString stringWithFormat:#"%#",[reversedArray objectAtIndex:section]];
NSString *newString = [dateString substringToIndex:[dateString length]-15];
NSString *string =[NSString stringWithFormat:#"%#",newString];
[label setText:string];
[view addSubview:label];
[view setBackgroundColor:[UIColor colorWithRed:13/255.0f green:78/255.0f blue:102/255.0f alpha:1.0f]];
return view;
}
The numberOfRowsInSection method
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
NSString *dateString = [NSString stringWithFormat:#"%#",[reversedArray objectAtIndex:section]];
NSLog(#"%# = %#", [dateString substringToIndex:[dateString length]-15], [[fixtures objectAtIndex:section] valueForKey:#"date"]);
NSArray *filteredArray = [fixtures filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"date == %#",[dateString substringToIndex:[dateString length]-15]]];
return filteredArray.count;
}
cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FixtureCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil) {
cell = [[FixtureCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
cell.homeTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"home" ];
cell.awayTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"away" ];
}
take out this code from your if sentence
cell.homeTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"home" ];
cell.awayTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"away" ];
you are reusing cells so the condition cell=nil will no be true always.
Also use indexPath.section for to know which data you should take for fill your cell
Assign label values outside if (cell == nil) reuse cell Identifier not enter the loop after cell creation
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FixtureCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil) {
cell = [[FixtureCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
}
cell.homeTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"home" ];
cell.awayTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"away" ];
return cell;
}
Change this method cellForRowAtIndexPath method:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
FixtureCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell"];
if (cell == nil)
{
cell = [[FixtureCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:#"cell"];
}
cell.homeTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"home"];
cell.awayTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"away"];
return cell;
}
If you are using custom cell then try this
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *simpleTableIdentifier = #"FixtureCell";
FixtureCell *cell = (FixtureCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:#"FixtureCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.homeTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"home"];
cell.awayTeamLabel.text = [[fixtures objectAtIndex:indexPath.row] objectForKey:#"away"];
return cell;
}

How to add a search bar and search display to an rss feed in UItableview

I created an RSS reader that parses from a .xml file. I am trying to create a search bar and search display controller, but am not sure how to search the objectForKey "title" or objectForKey "summary" within the UITableView.
Any help would be greatly appreciated.
The numberOfRowsInSection and cellForRowAtIndexPath looked like this:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return self.parseResults.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Check if cell is nil. If it is create a new instance of it
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
// Configure titleLabel
cell.textLabel.text = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"title"];
cell.textLabel.numberOfLines = 2;
//Configure detailTitleLabel
cell.detailTextLabel.text = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"summary"];
cell.detailTextLabel.numberOfLines = 2;
//Set accessoryType
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//Set font and style
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
return cell;
}
I recently tried to follow this sample project - https://github.com/deepthit/TableViewSearch.git - based on a suggestion.
My code then looked like this:
#interface QldRecentJudgmentsViewController () {
__strong NSArray *mFilteredArray_;
__strong UISearchBar *mSearchBar_;
__strong UISearchDisplayController *mSearchDisplayController_;
}
#end
#implementation ViewController
#synthesize parseResults = _parseResults, HUD;
- (void)viewDidLoad {
[super viewDidLoad];
mSearchBar_ = [[UISearchBar alloc] initWithFrame:CGRectMake(0,
0,
self.view.bounds.size.width,
44)];
mSearchBar_.delegate = self;
mSearchBar_.placeholder = #"search";
self.tableView.tableHeaderView = mSearchBar_;
mSearchDisplayController_ = [[UISearchDisplayController alloc] initWithSearchBar:mSearchBar_
contentsController:self];
mSearchDisplayController_.searchResultsDelegate = self;
mSearchDisplayController_.searchResultsDataSource = self;
mSearchDisplayController_.delegate = self;
}
#pragma mark - Table view data source
- (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 self.parseResults.count;
if (tableView == self.searchDisplayController.searchResultsTableView ||
[mFilteredArray_ count] > 0)
{
return [mFilteredArray_ count];
}
return parseResults.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
id result;
if (tableView == self.searchDisplayController.searchResultsTableView ||
[mFilteredArray_ count] > 0)
{
result = [mFilteredArray_ objectAtIndex:indexPath.row];
}
else
{
result = [parseResults objectAtIndex:indexPath.row];
}
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
//Check if cell is nil. If it is create a new instance of it
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
// Configure titleLabel
cell.textLabel.text = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"title"];
cell.textLabel.numberOfLines = 2;
//Configure detailTitleLabel
cell.detailTextLabel.text = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"summary"];
cell.detailTextLabel.numberOfLines = 2;
//Set accessoryType
//cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
//Set font and style
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
return cell;
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *url = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"link"];
NSString *title = [[self.parseResults objectAtIndex:indexPath.row] objectForKey:#"title"];
WebViewController *viewController = [[WebViewController alloc] initWithURL:url title:title];
[self.navigationController pushViewController:viewController animated:YES];
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - UISearchBarDelegate
- (void)searchBar:(UISearchBar *)searchBar
textDidChange:(NSString *)searchText {
if ([searchText length] == 0)
{
[self.tableView reloadData];
return;
}
NSPredicate *predicate = [NSPredicate predicateWithFormat:#"SELF.title contains[cd] %# OR SELF.summary contains[cd] %#", searchText, searchText];
mFilteredArray_ = [self.parseResults filteredArrayUsingPredicate:predicate];
[self.tableView reloadData];
}
- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
mFilteredArray_ = nil;
[self.tableView reloadData];
}
However, when I follow this the RSS feed does not load anymore in the tableview, so there are no results. Nevertheless when I try to search it does not correctly search the "title" or "summary" and the search results do not appear correctly -the cells are not neatly aligned after searching for something and getting results. Also, the only way to see RSS in the tableview is to search for any generic string, but once you press cancel in the search bar the RSS feed disappears and shows an empty tableview.
Thanks for any help in advance.

Xcode - Selected rows in table view does'nt retains its state

I am creating multiple lists like questions and answer session, question with multiple answers in table rows. But whenever I select a row other questions answers are also get selected and when I came back to same all the selections are gone. So how to avoid this ? Please help.
my code is,
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(val==1)
{
checkedArr=[[NSMutableArray alloc] init];
for (int i = 0; i<17; i++)
{
[checkedArr addObject:#"1"];
}
NSLog(#"Checked arr size %i",[checkedArr count]);
return 17;
}
else if(val==2)
{
checkedArr=[[NSMutableArray alloc] init];
for (int i = 0; i<13; i++)
{
[checkedArr addObject:#"1"];
}
return 13;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = [NSString stringWithFormat:#"Cell%i",indexPath.row];
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if(cell==nil)
{
cell= [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
cell.textLabel.numberOfLines = 0;
cell.textLabel.font = [UIFont fontWithName:#"Helvetica" size:14.0];
}
cell.textLabel.font = [UIFont fontWithName:#"Helvetica-Bold" size:18.0];
UIView *selectionColor = [[UIView alloc] init];
selectionColor.backgroundColor = [UIColor colorWithRed:99/255.0f green:209/255.0f blue:248/255.0f alpha:1.0];
cell.selectedBackgroundView = selectionColor;
if([[checkedArr objectAtIndex:indexPath.row] isEqual:#"0"])
{
cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tick.png"]];
[checkedArr addObject:indexPath];
NSLog(#"checkedArr 0000000");
}
else if ([[checkedArr objectAtIndex:indexPath.row] isEqual:#"1"])
{
cell.accessoryView.hidden=TRUE;
//cell.accessoryView=Nil;
[checkedArr removeObject:indexPath];
NSLog(#"checkedArr 111111");
}
cell.textLabel.frame=CGRectMake(75.0, 50.0, 150.0, 20.0);
cell.textLabel.text=[listArray objectAtIndex:indexPath.row];
NSLog(#"Checked arr size %i",[checkedArr count]);
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
cell=[questionTable cellForRowAtIndexPath:indexPath];
[checkedArr replaceObjectAtIndex:indexPath.row withObject:#"0"];
if([[checkedArr objectAtIndex:indexPath.row] isEqual:#"0"])
{
cell.accessoryView=[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"tick.png"]];
[checkedArr addObject:indexPath];
NSLog(#"checkedArr 0000000");
}
else if ([[checkedArr objectAtIndex:indexPath.row] isEqual:#"1"])
{
cell.accessoryView=nil;
[checkedArr removeObject:indexPath];
NSLog(#"checkedArr 111111");
}
[questionTable deselectRowAtIndexPath:indexPath animated:YES];
//[self.questionTable reloadData];
NSLog(#"Val is %i",val);
NSLog(#"selected is %#",[listArray objectAtIndex:indexPath.row]);
// NSLog(#"Checked arr descripton %#",[checkedArr description]);
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
cell.accessoryView = nil;
}

adding prefix tel: to phone number variable from array

How I can add prefix tel:65 to my phone number, that I fetched from address book in array.
If I do this in viewdidload it's getting null
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", phoneNumbers]];
NSLog(#"Some Text %#", phoneUrl);
NSLog(#"Phone Numbers %#", phoneNumbers);
Here phoneNumbers is array with numbers per each contact
Udate:
- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"BG.jpg"]]];
[detailTableView setBackgroundColor:[UIColor clearColor]];
detailTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
ShadowTable *Shadow = [[ShadowTable alloc] init];
[Shadow ForTableView:detailTableView ForView:self.view HeaderAlpha:0.3 FooterAlpha:0.6];
for(int i = 0 ; i <[phoneNumbers count]; i++)
{
NSURL *phoneUrl = [NSURL URLWithString:[NSString stringWithFormat:#"tel:%#", [phoneNumbers objectAtIndex:i]]];
NSLog(#"Phone with URL %#", phoneUrl);
NSLog(#"Phone Numbers %#", phoneNumbers);
}
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [phoneTypes count];
}
- (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];
}
UILabel *typeLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 40)];
typeLabel.text = [phoneTypes objectAtIndex:indexPath.row];
[typeLabel setBackgroundColor:[UIColor clearColor]];
[cell addSubview:typeLabel];
UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(130, 10, 170, 40)];
numberLabel.text = [phoneNumbers objectAtIndex:indexPath.row];
[numberLabel setBackgroundColor:[UIColor clearColor]];
[cell addSubview:numberLabel];
if (indexPath.row %2 == 0) {
cell.contentView.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.95 alpha:1.0];
} else {
cell.contentView.backgroundColor = [UIColor colorWithRed:0.9 green:0.9 blue:0.9 alpha:1.0];
}
//cell.textLabel.text = [phoneNumbers objectAtIndex:indexPath.row];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
You are using an array not a string. So you need to access all elements of array to add as suffix.
Use this :
for(int i = 0 ; i <[phoneNumbers count]; i++)
{
NSString *str = [#"tel:" stringByAppendingFormat:#"%#",[phoneNumbers objectAtIndex:i]];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *phoneUrl = [NSURL URLWithString:str];
NSLog(#"Some Text %#", phoneUrl);
}
EDIT : Url was null because there were spaces in "2013-05-31 14:58:24.759 GTCallBack[8225:c07]" so encode it to remove spaces.
Hope it helps you.

tableView and how to correctly use "Load more..."

I'm have kind of a really small and annoying problem. (No pun intended)
I kind seem to find my mistake. I also asked in chat, but we couldn't find the solution. I got the "Load more..." for my tableView from Abizerns github and implemented it. It works, except for the part, that when it starts up I have to click "Load more...". So on start it doesn't show me the first entries of the tableView until I clicked on "Load more...". You can see my annoyance. Maybe someone can spot my mistake, so that the tableView actually loads the first ten entries on start up.
#define kNumberOfItemsToAdd 10
#define PADDING 10.0f
#interface Main ()
#end
#implementation Main
#synthesize tabelle;
- (id)initWithStyle:(UITableViewStyle)style
{
self = [super initWithStyle:style];
if (self) {
// Custom initialization
}
numberOfItemsToDisplay = kNumberOfItemsToAdd;
return self;
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
if (numberOfItemsToDisplay == [tabelle count]) {
return 1;
}
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == 0) {
return numberOfItemsToDisplay;
} else {
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 6;
cell.detailTextLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.detailTextLabel.numberOfLines = 1;
}
if (indexPath.section == 0) {
cell.textLabel.font = [UIFont fontWithName:#"Verdana" size:14.0];
cell.detailTextLabel.font = [UIFont fontWithName:#"Verdana" size:12.0];
NSString *TableText = [[NSString alloc] initWithFormat:#"%#", [[tabelle objectAtIndex:indexPath.row] Name]];
NSString *TableText2 = [[NSString alloc] initWithFormat:#"%#", [[tabelle objectAtIndex:indexPath.row] m_m]];
NSString *cellValue = [NSString stringWithFormat:#"%#", TableText2];
NSString *cellValue2 = [NSString stringWithFormat:#"by: %#", TableText];
cell.textLabel.text = cellValue;
cell.detailTextLabel.textColor = [UIColor colorWithRed:0.196f green:0.3098f blue:0.52f alpha:1.f];
cell.detailTextLabel.text = cellValue2;
} else {
cell.textLabel.text = [NSString stringWithFormat:#"Next %d items", kNumberOfItemsToAdd];
cell.textLabel.textAlignment = UITextAlignmentCenter;
cell.textLabel.textColor = [UIColor colorWithRed:0.196f green:0.3098f blue:0.52f alpha:1.f];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14.f];
}
return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *text = [[self.tabelle objectAtIndex:indexPath.row] m_m];
CGSize textSize = [text sizeWithFont:[UIFont systemFontOfSize:14.0f] constrainedToSize:CGSizeMake(self.tableView.frame.size.width - PADDING * 3, 1000.0f)];
return textSize.height + PADDING * 3;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 1) {
NSUInteger i, totalNumberOfItems = [tabelle count];
NSUInteger newNumberOfItemsToDisplay = MIN(totalNumberOfItems, numberOfItemsToDisplay + kNumberOfItemsToAdd);
NSMutableArray *indexPaths = [[NSMutableArray alloc] init];
for (i=numberOfItemsToDisplay; i<newNumberOfItemsToDisplay; i++) {
[indexPaths addObject:[NSIndexPath indexPathForRow:i inSection:0]];
}
numberOfItemsToDisplay = newNumberOfItemsToDisplay;
[tableView beginUpdates];
[tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationTop];
if (numberOfItemsToDisplay == totalNumberOfItems) {
[tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationTop];
}
[tableView endUpdates];
// Scroll the cell to the top of the table
if (newNumberOfItemsToDisplay < totalNumberOfItems) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 200000000), dispatch_get_main_queue(), ^(void){
[tableView scrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionTop animated:YES];
});
[tableView deselectRowAtIndexPath:indexPath animated:YES];
} else {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 200000000), dispatch_get_main_queue(), ^(void){
[tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:totalNumberOfItems-1 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
});
}
}
}
I haven't used a "Load more..." implementation, but maybe what you need is add [self.tabelle reloadData] in your - (void)viewWillAppear:(BOOL)animated method.
What method gets called when you click "Load more..."? Can you not programmatically call that method when the tableview is loaded?

Resources