I have to store specific movies url in database to show in collectionView which is inside a table cell. Whenever it compiles to this line [API userMovies:catId getResponseBlock:^(id responseObject) it goes to this line _movieImages = [Movies MR_findAll] instead of responseBlock.
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
static int number = 0;
catId = [[_movieCategories objectAtIndex:number] categoryId];
number++;
[API userMovies:catId getResponseBlock:^(id responseObject)
{
[Movies MR_truncateAll];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
NSArray *responseArray = [responseObject objectForKey:#"items"];
[Movies MR_importFromArray:responseArray];
[[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];
} forFailureBlock:^(id failureObject) {
// self.errorMsg.text = #"Failed to load movies!";
}];
_movieImages = [Movies MR_findAll];
return _movieImages.count;
}
cellForItemAtIndexPath:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
CategoryCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:#"CatCell" forIndexPath:indexPath];
NSURL *url = [NSURL URLWithString:[[_movieImages objectAtIndex:indexPath.row] cover_img]];
NSNumber *rate = [[_movieImages objectAtIndex:indexPath.row]rating];
[cell.imageView setImageWithURL:url];
_categoryCollection.showsHorizontalScrollIndicator = NO;
return cell;
}
cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *categoryTable = #"CategoryCell";
// Configure the cell...
CategoryMovieCell *cell = [tableView dequeueReusableCellWithIdentifier:categoryTable];
cell.categoryMovie.text = [[_movieCategories objectAtIndex:(indexPath.row-1)] name];
return cell;
}
Related
I'm having a weird issue on UITableView delete action since iOS 11.
Here's the relevant TableView code :
#implementation ChatMessageListViewController(TableView)
#pragma mark - table view datasource/delegate
- (NSArray<UITableViewRowAction *> *) tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath{
NSMutableArray *rowActions = [NSMutableArray array];
UITableViewRowAction *delete = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:#"Delete" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self deleteMessageAtIndexPath:indexPath];
}];
delete.backgroundColor = [UIColor redColor];
[rowActions addObject:delete];
return [rowActions copy];
}
- (void) deleteMessageAtIndexPath:(NSIndexPath *)indexPath {
NSString *threadID = [[self.messageArray objectAtIndex:indexPath.row] objectForKey:#"threadID"];
[self.tableView beginUpdates];
[self.messageArray removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:#[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView endUpdates];
#weakify(self);
[UIUtil showLoadingHudWithText:WELocalString(#"message_remove_thread_loading_text", #"Deleting...", #"删除中...")];
[[AsyncUtil sharedInstance] dispatch_background_network:^{
DBManager *db = [[DBManager alloc] init];
[db deletetableData:[NSString stringWithFormat:#"singleChat WHERE threadID = '%#' ",threadID] ];
[[MemChatThreadMessages sharedInstance] removeThread:threadID];
NSDictionary * result = [Network deleteChatThread:threadID forEmail:[WEUtil getEmail]];
[[AsyncUtil sharedInstance] dispatch_main:^{
[UIUtil hideLoadingHuds];
#strongify(self);
if(self == nil) return ;
if([result[#"result"] isEqualToString:#"success"]){
}else{
[UIUtil showErrorMessage:WELocalString(#"message_remove_thread_error", #"Cannot delete this thread", #"不能删除该会话!")];
}
[self.tableView reloadData];
}];
}];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return [self.messageArray count];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *messageInfo = [self.messageArray objectAtIndex:indexPath.row];
if ([(NSString *)[messageInfo objectForKey:#"isAnnouncement"] isEqualToString:#"1"]) {
return 80;
}else if ([[messageInfo objectForKey:#"chatTag"] isValidString]){
return 80;
}else if([self isSpecialMessage:messageInfo]){
return 80;
}else{
return 67;
}
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = #"message";
if(self.events == nil){
NSDictionary * d = [WEUtil getMyEventListCache];
self.events = [[NSMutableDictionary alloc] init];
for(NSDictionary * eventSummary in d[#"events"]){
NSString * eventID = eventSummary[#"eventid"];
[self.events setObject:eventSummary forKey:eventID];
}
}
UserMessageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil){
cell = [[UserMessageTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier];
}
if(indexPath.row >= [self.messageArray count]){
TERMINATE_WITH_NIL_CELL;
}
NSDictionary *messageInfo = [self.messageArray objectAtIndex:indexPath.row];
if(![self isSpecialMessage:messageInfo]){
[cell configureCellWithMessageDict:messageInfo];
}else{
[cell configureCellWithNewMessageDict:messageInfo withEvents:self.events];
}
return cell;
}
#pragma mark - Navigation
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSDictionary *msgThreadDict = [self.messageArray objectAtIndex:indexPath.row];
if(![self isSpecialMessage:msgThreadDict]){
[self tableView:tableView didSelectNormalRowAtIndexPath:indexPath];
}else{
NSString * event = msgThreadDict[#"event"];
if([event isValidString]){
if([event isEqualToString:#"no_event_messages"]){
[UIUtil showErrorMessage:#"no event id"];
}else{
[BackendTracking trackingWithAction:#"open_special" withLabel:#"threads_list"];
SpecialTopicListViewController * special = [[SpecialTopicListViewController alloc] init];
special.tracking_src = #"tab";
[self.navigationController pushViewController:special animated:YES];
}
}
}
}
-(void) tableView:(UITableView *)tableView didSelectNormalRowAtIndexPath:(NSIndexPath *)indexPath{
NSDictionary *msgThreadDict = [self.messageArray objectAtIndex:indexPath.row];
NSString *threadID = [msgThreadDict objectForKey:#"threadID"];
NSString *jid = [msgThreadDict objectForKey:#"jid"];
[GATracking trackCategory:#"message" withAction:#"thread_list_item_click" withLabel:threadID];
[[MemChatThreadMessages sharedInstance] setCurrentThreadID:threadID];
PrivateMessageViewController * chatVC = [[PrivateMessageViewController alloc] init];
chatVC.threadID = threadID;
chatVC.targetJID = jid;
chatVC.targetName = [msgThreadDict objectForKey:#"name"];
chatVC.unreadMsgNumber = [[self.messageArray objectAtIndex:indexPath.row][#"unreadCnt"] integerValue];
if ([(NSString *)[msgThreadDict objectForKey:#"isGroup"] isEqualToString:#"1"]) {
chatVC.isGroup = YES;
}else{
chatVC.isGroup = NO;
}
chatVC.src = #"list";
WELogInfo(#"click message");
[self.navigationController pushViewController:chatVC animated:YES];
}
#end
With the update and the changes using those trailing swipe actions there is another View appended before each time I delete an entry (until it doesn't work anymore). I've tried disabling the full trail or implementing iOS 11 trailingSwipeActionsConfigurationForRowAtIndexPath but I can't resolve this issue so far.
Do you see something wrong in the code? The main controller code is in another file.
Try reloading after you delete, after this line
[self.tableView endUpdates];
I think you removed the data from messageArray but as you are not reloading just after that so table view count is still 2 and you are reloading inside the block which might be taking time.
And one more thing you already removing data from messageArray, and then removing from db, So if you fail to remove it from db you are showing its not removed but for user it will be removed, as its no longer in message array
Two bug in this code.
First one when i delete Row in tableview delete last row not selected row.
Second Bug is when try to delete more than one row that time will delete successfully but when reload tableview Only one row deleted. Rest row will appear again.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return result.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (IBAction)action:(id)sender {
[_myTableView setEditing:YES animated:YES];
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) {
[result removeObjectAtIndex:indexPath.row];
[tableView reloadData];
[spinner startAnimating];
NSString *id = [profile objectForKey:#"user_id"];
NSString *tb =tid;
NSString *string = [NSString stringWithFormat:#"userid=%#&topiid=%#",id,tb];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"myDeleteUrl"]];
NSData *data = [string dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[request setHTTPMethod:#"POST"];
[request setHTTPBody : data];
NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration
defaultSessionConfiguration]]; [[session dataTaskWithRequest : request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSDictionary *JSON= [NSJSONSerialization JSONObjectWithData :data options :NSJSONReadingMutableContainers error: nil];
NSArray *alertArray = [JSON objectForKey:#"deletebookmark"];
for (NSDictionary *alert in alertArray ){
if ([[alert objectForKey:#"status"] isEqualToString:#"done"]) {
NSLog(#"done");
[spinner stopAnimating];
}
else{
NSLog(#"notDone");
[spinner stopAnimating];
}
}
}]resume];
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10]; name.text = [result objectAtIndex : indexPath.row];
}
name.tag=indexPath.row;
return cell;
}
In this datasource method, you have used a "if" condition, and due to your cell is reusable cell, so you have to use the else part too in this data source method.
Like
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (!(cell == nil)) {
name = (UILabel *)[cell viewWithTag:10]; name.text = [result objectAtIndex : indexPath.row];
}
else{
name.tag=indexPath.row;
}
return cell;
}
Thanks
Try this way
[result removeObjectAtIndex:indexPath.row];
[tableView reloadData];// comment this line above code
[spinner stopAnimating];
//After that you can add
[tableView reloadData]; // above stopanimating line.
Add this cellForRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:#"cell" forIndexPath : indexPath];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:#"cell"];
}
name = (UILabel *)[cell viewWithTag:10];
name.text = [result objectAtIndex : indexPath.row];
name.tag=indexPath.row;
return cell;
}
I am downloading the images from parse and after that I am showing that images in uicollection view but when I scroll the collection view it hangs. Here is my code
-(void)viewWillAppear:(BOOL)animated
{
CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat height = CGRectGetHeight(screen);
PFQuery * query = [PFQuery queryWithClassName:#"Static_Wallpaper"];
[query selectKeys:#[#"thumbnail"]];
if (height == 480) {
[query selectKeys:#[#"image4s"]];
}
else{
[query selectKeys:#[#"image6s"]];
}
[query findObjectsInBackgroundWithBlock:^(NSArray * objects, NSError * error){
if (!error) {
[imgArry arrayByAddingObjectsFromArray:objects];
imgArry = [[NSMutableArray alloc] initWithArray:objects];
NSLog(#"%lu",(unsigned long)imgArry.count);
[cllectionView reloadData];
}
}];
}
and Here is the code populating the images in collection view
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return imgArry.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = #"Cell";
CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
PFObject *imageObject = [imgArry objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:#"image4s"];
[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
if (!error){
NSLog(#"is there any data? %#", data);
cell.imgView.image = [UIImage imageWithData:data];
;
}
else {
NSLog(#"no data!");
}
}];
return cell;
}
By adding SDWebimage you need to do code like following:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
static NSString *identifier = #"Cell";
CustomCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
PFObject *imageObject = [imgArry objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:#"image4s"];
NSString *UserProfile = [file url];
if([[SDWebImageManager sharedManager] diskImageExistsForURL:[NSURL URLWithString:UserProfile]])
{
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:[NSURL URLWithString:UserProfile]];
UIImage *image = [[SDImageCache sharedImageCache] imageFromDiskCacheForKey:key];
cell.imgView.image=image;
}
else
{
cell.imgView.image=[UIImage imageNamed:#"UserUpdationImageCell.png"];
[cell.imgView sd_setImageWithURL:[NSURL URLWithString:UserProfile] placeholderImage:[UIImage imageNamed:#"UserUpdationImageCell.png"]];
}
return cell;
}
Your download task may block the main thread.You can try to use SDWebImage or asynchrous download task and display image
I make dictionary in iOS, I get data from JSON url. I have problem with correctly display result of word from SearchBar. For example when I type something in searchBar and click on some result , always display value of first result.
Below I put my screen to present this problem.
On the second screen I click on Ruby on Rails and show me first of result "Objective C", why (Objective C is a first result in JSON file)?
And it's my code: http://pastebin.com/EPVTpF9U
#pragma mark - Navigation
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"pushDetailView"]){
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *modalVC = (DetailViewController*)segue.destinationViewController;
modalVC.detailArray = [self.finalResultArray objectAtIndex:indexPath.row];
}
}
#pragma mark - UISearchDisplayDelegate
// register a cell reuse identifier for the search results table view
-(void)searchDisplayController:(UISearchDisplayController *)controller
didLoadSearchResultsTableView:(UITableView *)tableView {
[tableView registerClass:[UITableViewCell class]
forCellReuseIdentifier:#"Cell"];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(tableView == self.tableView){
return self.finalResultArray.count;
}else{
return self.results.count;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdetifier = #"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdetifier forIndexPath:indexPath];
if(!cell){
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdetifier];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
if(tableView == self.tableView){
cell.textLabel.text = [[self.finalResultArray objectAtIndex:indexPath.row] objectForKey:#"expression"];
cell.detailTextLabel.text = [[self.finalResultArray objectAtIndex:indexPath.row] objectForKey:#"meaning"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else{
cell.textLabel.text = [[self.results objectAtIndex:indexPath.row] objectForKey:#"expression"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
UIView *customColorView = [[UIView alloc] init];
customColorView.backgroundColor = [UIColor colorWithRed:180/255.0
green:138/255.0
blue:171/255.0
alpha:0.5];
cell.selectedBackgroundView = customColorView;
return cell;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[self performSegueWithIdentifier:#"pushDetailView" sender:self];
}
- (void)simpleJsonParsing
{
//-- Make URL request with server
NSHTTPURLResponse *response = nil;
NSString *jsonUrlString = [NSString stringWithFormat:#"https://uidictionary.herokuapp.com/phrases.json"];
NSURL *url = [NSURL URLWithString:[jsonUrlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
//-- Get request and response though URL
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
//-- JSON Parsing
NSArray *result = [[NSJSONSerialization JSONObjectWithData:responseData options:
NSJSONReadingMutableContainers error:nil] objectForKey:#"phrases"];
[self.finalResultArray removeAllObjects];
for (NSMutableDictionary *tmp in result)
{
NSMutableDictionary *temp = [NSMutableDictionary new];
[temp setObject:[tmp objectForKey:#"expression"] forKey:#"expression"];
[temp setObject:[tmp objectForKey:#"meaning"] forKey:#"meaning"];
[self.finalResultArray addObject:temp];
}
if (self.finalResultArray){
[self.tableView reloadData];
}
}
- (void)updateSearchResultsForSearchController:(UISearchController *)searchController {
self.results = [self.finalResultArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"%K contains[c] %#", #"expression", searchController.searchBar.text]];
NSLog(#"Filterd Array:-%#", self.results);
// hand over the filtered results to our search results table
UITableViewController *tableController = (UITableViewController *)self.searchController.searchResultsController;
tableController.tableView.dataSource = self;
tableController.tableView.delegate = self;
[tableController.tableView reloadData];
}
Just replace Bellow Code :-
self.results = [self.finalResultArray filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:#"%K BEGINSWITH[c] %#", #"expression", searchController.searchBar.text]];
#mechu911
Replace your method with below code.
-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
if([[segue identifier] isEqualToString:#"pushDetailView"]){
NSIndexPath * indexPath = [self.tableView indexPathForSelectedRow];
DetailViewController *modalVC = (DetailViewController*)segue.destinationViewController;
modalVC.detailArray = [self.result objectAtIndex:indexPath.row];
}
}
but you have to put check like
if(tableView == self.tableView){
modalVC.detailArray = [self.finalResultArray objectAtIndex:indexPath.row];}
else{modalVC.detailArray = [self.result objectAtIndex:indexPath.row];}
i am newbie in iOS and i know this Question is asked for many times but i am not getting solution.i made an application with tableview here is my tableview code Containing two section and i want to Fill this section with JSON Data.i made Two CustomCell. it Display well but i am not able to fill my JSON Parsing Data.
my code is.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0)
{
static NSString *CellIdentifierOne=#"CellOne";
CustumCell *cellOne =[tableView dequeueReusableCellWithIdentifier:CellIdentifierOne];
if (cellOne == nil)
{
NSArray *nibOne=[[NSBundle mainBundle]loadNibNamed:#"CustumCell" owner:self options:nil];
cellOne=[nibOne objectAtIndex:0];
cellOne.userInteractionEnabled=NO;
}
{
[cellOne.spinner startAnimating];
NSDictionary *dict = [self.imageArray objectAtIndex:indexPath.section];
NSString *img2=[dict valueForKey:#"front_image"];
[cellOne.storeImage sd_setImageWithURL:[NSURL URLWithString:[img2 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]] placeholderImage:[UIImage imageNamed:#"Setting.png"] options:SDWebImageHighPriority completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL)
{
[cellOne.spinner stopAnimating];
cellOne.spinner.hidesWhenStopped=YES;
}];
}
return cellOne;
}
else
{
static NSString *CellIdentifierTwo=#"CellTwo";
TableCell *cellTwo=[tableView dequeueReusableCellWithIdentifier:CellIdentifierTwo];
if (cellTwo == nil)
{
NSArray *nibTwo=[[NSBundle mainBundle]loadNibNamed:#"TableCell" owner:self options:nil];
cellTwo=[nibTwo objectAtIndex:0];
cellTwo.userInteractionEnabled=NO;
}
return cellTwo;
}
return nil;
}
And Here Tableview section is Two and also code for numberofRow is
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section == 0)
{
return 1;
NSLog(#"Images %#",self.imageArray);
}
else
{
return self.imageArray.count - 1;
}
}
when there is no any Data then it Shows as i want, but i am not able to fill my Data Please provide me any Solution.
#AshishGabani
look at the below code, what i understand for your requirement
I have taken an array, contains values like this
NSMutableArray *imageArray = [[NSMutableArray alloc]initWithObjects:#"1",#"2",#"3",nil];
Next TableView Methods:
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if (section==0) return 1;
return imageArray.count-1;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 2;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *simpleTableIdentifier = #"Simple";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
if(indexPath.section==0) {
cell.textLabel.text = [imageArray objectAtIndex:indexPath.row];
} else {
cell.textLabel.text = [imageArray objectAtIndex:indexPath.row+1];
}
return cell;
}
Just Comment you existing code and Copy this code and Paste your Xcode ViewController and Run the simulator, I think i reached your requirement .