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

  • Home
  • SEARCH
  • 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 8289015
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:24:32+00:00 2026-06-08T12:24:32+00:00

I have two problems (in fact one – my code sucks): My table takes

  • 0

I have two problems (in fact one – my code sucks):

  1. My table takes a long time to load(about 5 seconds)
  2. She is dreadfully poor

Any ideas?

My tableView methods:

// Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    RefreshDelegate *RefreshProtocol = [[RefreshDelegate new] autorelease];
    RefreshProtocol.delegate = self;

return [[RefreshProtocol returnDataForTable] count];

}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    RefreshDelegate *RefreshProtocol = [[RefreshDelegate new] autorelease];
    RefreshProtocol.delegate = self;


    NSArray *curent = [self curent:section];
    return [curent count];
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section { 
    RefreshDelegate *RefreshProtocol = [[RefreshDelegate new] autorelease];
    RefreshProtocol.delegate = self;

    return [[[RefreshProtocol returnDataForTable] allKeys] objectAtIndex:section];
}

- (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] autorelease];
    }

    NSArray *curent = [self curent:indexPath.section];
    cell.textLabel.text = [curent objectAtIndex:indexPath.row];

    return cell;
}

- (NSArray*)curent:(NSInteger)index {
    RefreshDelegate *RefreshProtocol = [[RefreshDelegate new] autorelease];
    RefreshProtocol.delegate = self;

    NSArray *keys = [[RefreshProtocol returnDataForTable] allKeys];
    NSString *curentKey = [keys objectAtIndex:index];
    NSArray *curent = [[RefreshProtocol returnDataForTable] objectForKey:curentKey];
    return curent;
}

My RefreshProtocol methods:

#define MaxCountPair 7
-(NSDictionary *)returnDataForTable{  
    NSMutableArray *day_1 = [NSMutableArray arrayWithCapacity:MaxCountPair];
    NSMutableArray *day_2 = [NSMutableArray arrayWithCapacity:MaxCountPair];
    NSMutableArray *day_3 = [NSMutableArray arrayWithCapacity:MaxCountPair];
    NSMutableArray *day_4 = [NSMutableArray arrayWithCapacity:MaxCountPair];
    NSMutableArray *day_5 = [NSMutableArray arrayWithCapacity:MaxCountPair];
    NSMutableArray *day_6 = [NSMutableArray arrayWithCapacity:MaxCountPair];


    // Analysis db and write array today
    NSArray *array = [SQLiteAccess selectManyRowsWithSQL:@"select * from schedule"];
    for (int i = 0; i < [array count]; i++) {
        NSDictionary *dictionary = [array objectAtIndex:i];

        if ([self checkOverlapDigit:[[[NSUserDefaults standardUserDefaults] valueForKey:@"numberWeek"] objectForKey:@"numberWeek"]:[dictionary objectForKey:@"week"]] && [self checkOverlapDigit:[self subgroupToInt]:[dictionary objectForKey:@"subgroup"]]) {
            if ([self checkDay:[[dictionary objectForKey:@"day"] intValue]]) {
                [day_1 addObject:[dictionary objectForKey:@"subject"]]; 
            }
            else {
                if ([self checkDay:[[dictionary objectForKey:@"day"] intValue] - 1]) {
                    [day_2 addObject:[dictionary objectForKey:@"subject"]];
                }
                else {
                    if ([self checkDay:[[dictionary objectForKey:@"day"] intValue] - 2]) {

                        [day_3 addObject:[dictionary objectForKey:@"subject"]];
                    }
                    else {
                        if ([self checkDay:[[dictionary objectForKey:@"day"] intValue] - 3]) {
                            [day_4 addObject:[dictionary objectForKey:@"subject"]];
                        }
                        else {
                            if ([self checkDay:[[dictionary objectForKey:@"day"] intValue] - 4]) {
                                [day_5 addObject:[dictionary objectForKey:@"subject"]];
                            }
                            else {
                                if ([self checkDay:[[dictionary objectForKey:@"day"] intValue] - 5]) {
                                    [day_6 addObject:[dictionary objectForKey:@"subject"]];
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    NSDictionary *days = [NSDictionary dictionaryWithObjectsAndKeys:day_1, @"1", day_2, @"2", day_3, @"3", day_4, @"4", day_5, @"5", day_6, @"6", nil];


    return days;
}

-(NSString *)removeAllButDigit:(NSString *)originalString{
    // Remove all but digit
    NSMutableString *strippedString = [NSMutableString 
                                       stringWithCapacity:originalString.length];

    NSScanner *scanner = [NSScanner scannerWithString:originalString];
    NSCharacterSet *numbers = [NSCharacterSet 
                               characterSetWithCharactersInString:@"1234"];

    while ([scanner isAtEnd] == NO) {
        NSString *buffer;
        if ([scanner scanCharactersFromSet:numbers intoString:&buffer]) {
            [strippedString appendString:buffer];
        } else {
            [scanner setScanLocation:([scanner scanLocation] + 1)];
        }
    }

    return strippedString;
}

-(BOOL)checkDay:(NSInteger)day{
    NSString *currentDay = nil;
    switch (day) {
        case 1:
            currentDay = NSLocalizedString(@"_monday", nil);
            break;
        case 2:
            currentDay = NSLocalizedString(@"_tuesday", nil);
            break;
        case 3:
            currentDay = NSLocalizedString(@"_wednesday", nil);
            break;
        case 4:
            currentDay = NSLocalizedString(@"_thursday", nil);
            break;
        case 5:
            currentDay = NSLocalizedString(@"_friday", nil);
            break;
        case 6:
            currentDay = NSLocalizedString(@"_saturday", nil);
            break;
        default:
            break;
    }

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];  
    [dateFormatter setDateFormat:@"EEEE"];
    if ([currentDay isEqualToString:[dateFormatter stringFromDate:[NSDate date]]]) {
        return YES;
    }
    return NO;
}


-(BOOL)checkOverlapDigit:(NSString *)smallerString:(NSString *)largerString{
    if ([largerString isEqualToString:@"0"]) {
        return YES;
    }

    NSInteger intSmaller = [[self removeAllButDigit:smallerString] intValue];
    NSInteger intLarger = [[self removeAllButDigit:largerString] intValue];

    while (1) {
        if (intLarger % 10 != 0) {
            NSInteger sedimentWeek = intLarger % 10;
            if (sedimentWeek == intSmaller) {
                return YES;
            }
            intLarger /= 10;
        }
        else {
            if (intLarger / 10 != 0) {
                intLarger /= 10;
                if (intLarger == intSmaller) {
                    return YES;
                }
            }
            else {
                return NO;
            }
        }
    }
}

-(NSString *)subgroupToInt{
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"subgroupValue"] isEqualToString: @"subgroupValue1"]) {
        return @"1";
    }
    else
        if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"subgroupValue"] isEqualToString: @"subgroupValue2"]) {
            return @"2";

        }
        else
            if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"subgroupValue"] isEqualToString: @"subgroupValue3"]) {
                return @"3";
            }
    return @"4";
}

And SQLiteAccess class: .h, .m

  • 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-08T12:24:33+00:00Added an answer on June 8, 2026 at 12:24 pm

    For starting… you can (you have) to create you object only once!! (in the constructor? In -viewDidLoad ?)

    Then in the tableView delegate methods you access your (unique) object.

    EDIT:
    Adds a property in your class:

    @property (nonatomic, strong) RefreshDelegate* refreshProtocol;
    

    In your -viewDidLoad method add

    -(void)viewDidLoad
    {
        [super viewDidLoad];
        self.refreshProtocol = [[RefreshDelegate new] autorelease];
        self.refreshProtocol.delegate = self;
    }
    

    Now:

    - (NSArray*)curent:(NSInteger)index {    
    
        NSArray *keys = [[self.refreshProtocol returnDataForTable] allKeys];
        NSString *curentKey = [keys objectAtIndex:index];
        NSArray *curent = [[self.refreshProtocol returnDataForTable] objectForKey:curentKey];
        return curent;
    }
    
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
        NSArray *curent = [self curent:section];
        return [curent count];
    }
    

    … and correct the other methods…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems trying to perform a query. I have two tables, one
I have two problems. problem one: I am trying to create a registeration form
I'm using devexpress and i have two problems. My insert stored procedure work fine.
I have my program that can draw rectangles. I have two problems I can't
I have two cmake-related problems: first, I can't make it to find the includes
I have some localization problems in my webpage. There are basically two problems (that
We are having some problems deploying our WCF services into IIS7. We have two
Problem: I have two array where one produce a category and the second produce
I have two tables on mysql: users, and management. The users table has a
Suppose I have two comboboxes. One for the lower-value and one for the upper

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.