Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7746069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T10:11:02+00:00 2026-06-01T10:11:02+00:00

I have TableView. My datasource is SQLite database. I’m trying to count a number

  • 0

I have TableView. My datasource is SQLite database. I’m trying to count a number of comments to some message (I know message id and it’s text) for numberOfRowsInSection: method.

-(NSInteger)numberOfCommentsForMessage:(NSIndexPath *)indexPath {
    MDAppDelegate *appDelegate = (MDAppDelegate *)[[UIApplication sharedApplication] delegate];
    Comments *comment = (Comments *)[appDelegate.comments objectAtIndex:indexPath.row];
    if (MessageID == [comment.messageID integerValue]) {
        numberOfCommentsForMessage++;
     }
    NSLog(@"number of comments = %i",numberOfCommentsForMessage);
    return numberOfCommentsForMessage;
}

It isn’t work even NSLog. I think this method should be called in viewDidLoad() but not sure that way is right.

Editing

Comments.h

@interface Comments : NSObject {
    NSString *messageID;
    NSString *commentText;
}

@property (nonatomic, retain) NSString *messageID;
@property (nonatomic, retain) NSString *commentText;

-(id)initWithName:(NSString *)mID commentText:(NSString *)cText;

MessageID I get from previous view:

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
          MessageText:(NSString *)messageText
          MessageDate:(NSString *)messageDate
            MessageID:(NSInteger)messageID;
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        MessageText = [NSString stringWithString:messageText];
        MessageDate = [NSString stringWithString:messageDate];
        MessageID = messageID;
    }
    return self;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T10:11:03+00:00Added an answer on June 1, 2026 at 10:11 am

    It would also be interesting to know exactly what’s not working. Does your application crash at NSLog or does it return the wrong message count?

    Since you’re returning numberOfCommentsForMessage from the method it would be desirable to reduce the scope of numberOfCommentsForMessage to a local variable within the method.

    -(NSInteger)numberOfCommentsForMessage:(NSIndexPath *)indexPath {
        NSInteger numberOfComments = 0;
        MDAppDelegate *appDelegate = (MDAppDelegate *)[[UIApplication sharedApplication] delegate];
        Comments *comment = (Comments *)[appDelegate.comments objectAtIndex:indexPath.row];
        if (MessageID == [comment.messageID integerValue]) {
            numberOfComments++;
         }
        NSLog(@"number of comments = %d",numberOfComments);
        return numberOfComments;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a tableview with a navigation bar at the top. I've added text
I have been trying to remove an object from the tableView I am working
I have an events app which gets events data from sqlite database and displays
I have a NSMutableDictionary as the datasource for my UITableView. I am trying to
I am not able to delete data from SQlite database. I have created a
I know how to connect the datasource of a TableView in a Sotryboard, but
I have a tableView that's loosely based on the DetailViewController in ye olde SQLiteBooks.
I have a tableview with large images that fill the cells and the row
I have a tableView and when the user is selecting one of the cells,
I have a tableview that occupies only the bottom third of my view. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.