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 7499251
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:46:09+00:00 2026-05-29T19:46:09+00:00

I am new in iOS objective c and now I build an app that

  • 0

I am new in iOS objective c and now I build an app that works with FtpServer to retrieve folder list and put in a UiTableView.

With this code I work with stream:

-(void) readStream {

CFURLRef ftpURL=(CFURLRef)url;

CFReadStreamRef readFTPStream=CFReadStreamCreateWithFTPURL(kCFAllocatorDefault, ftpURL);
CFReadStreamSetProperty(readFTPStream,kCFStreamPropertyFTPUserName,userName);
CFReadStreamSetProperty(readFTPStream,kCFStreamPropertyFTPPassword,password);
CFReadStreamSetProperty (readFTPStream,kCFStreamPropertyFTPUsePassiveMode,NO);

MyStreamInfo streamInformation;
streamInformation.readStream=readFTPStream;


CFStreamClientContext clientContext={0,self,NULL,NULL,NULL};

CFOptionFlags events= kCFStreamEventHasBytesAvailable | kCFStreamEventErrorOccurred |    kCFStreamEventEndEncountered;



BOOL flagOpen=CFReadStreamSetClient(readFTPStream, events,(void*)didStartReceiveList, &clientContext);


if (flagOpen) {


    CFReadStreamScheduleWithRunLoop(readFTPStream, CFRunLoopGetCurrent(), kCFRunLoopCommonModes);
    //CFReadStreamUnscheduleFromRunLoop(readFTPStream, CFRunLoopGetCurrent(), kCFRunLoopRunFinished);

}


if(!CFReadStreamOpen(readFTPStream)){
    NSLog(@"Could not open read stream");
}

NSLog(@"fine");

}

So I am the callbackFunction to receve event:

void didStartReceiveList(NSInputStream *stream,CFStreamEventTypeevent,CFStreamClientContext *clientContext) {


   //ViewController *self = (__bridge_transfer ViewController *)clientContext;


    ViewController *self=( ViewController *)clientContext;

switch(event) {
    case kCFStreamEventHasBytesAvailable:{

        [self readStreamData:(CFReadStreamRef)stream :clientContext];

    }
        break;
    case kCFStreamEventErrorOccurred: {

        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"iFTP" 
                                                      message:[self message]
                                                     delegate:self 
                                            cancelButtonTitle:@"OK" 
                                            otherButtonTitles:nil];
        [alert show];

    }

        break;
    case kCFStreamEventEndEncountered:{
        //reload data

         **here in the reload i receive Signal crash**

        [self.tb reloadData];




    }
        break;
    }

}

and this are the stream method

-(void) readStreamData:(CFReadStreamRef) stream :(CFStreamClientContext*)  context {


MyStreamInfo *info=context->info;    
int offset=0;

CFIndex bytesRead = CFReadStreamRead(stream, info->buffer + offset,kMyBufferSize-offset);

if (bytesRead < 0) {

    CFErrorRef err=CFReadStreamCopyError(stream);
    CFStringRef str=CFErrorCopyDescription(err);
    NSString *descr=(__bridge_transfer NSString *)str;

    self.message=[NSString stringWithString:descr];
    fprintf(stderr, "CFReadStreamRead returned %ld: %s.", bytesRead,strerror(errno));
    CFRelease(err);

} else if (bytesRead == 0) {



    self.message=[[NSString alloc ]initWithString:@"Nothing to read"];
    fprintf(stderr, "CFReadStreamRead returned %ld: %s.", bytesRead,strerror(errno));
    //CFReadStreamClose(stream);


}

int bufSize = bytesRead + offset;
int totalBytesRead=0;
totalBytesRead+= bufSize;

int totalBytesConsumed=0;
CFIndex bytesReturned;

const UInt8 *newBuffer=info->buffer+totalBytesConsumed;
NSDictionary *d=[[NSDictionary alloc]init];
if (bytesRead>0) {

    do {
        const UInt8 *buffRemaining=info->buffer+totalBytesConsumed;
        NSDictionary *dict=[[NSDictionary alloc] init];
        CFDictionaryRef dictionaryParsed=(__bridge_retained CFDictionaryRef)dict;
        bytesReturned=CFFTPCreateParsedResourceListing(NULL, newBuffer, bufSize, &dictionaryParsed);

        if (bytesReturned>0) {
            if (dictionaryParsed!=NULL) {

                d=(__bridge_transfer NSDictionary *)dictionaryParsed;
                NSString *name=[d valueForKey:(NSString *)kCFFTPResourceName];
                [self.listEntries addObject:name];


            }


            totalBytesConsumed += bytesReturned;
            bufSize -= bytesReturned;
            info->leftOverByteCount = bufSize; 
    ;        newBuffer=info->buffer+totalBytesConsumed;

        } 
        else if (bytesReturned == 0) {

            info->leftOverByteCount = bufSize;
            totalBytesRead -= info->leftOverByteCount;
            memmove(info->buffer, buffRemaining, info->leftOverByteCount);
        } 

        else if (bytesReturned == -1) {
            alert=[[UIAlertView alloc] initWithTitle:@"iFTP" 
                                             message:@"CFFTPCreateParsedResourceListing parse failure" 
                                            delegate:self 
                                   cancelButtonTitle:@"OK" 
                                   otherButtonTitles:nil];
            [alert show];
            break;
        }

    } while (bytesReturned>0 );

    //self.tb.delegate=self;
    //Add new records to the table
    //ViewController *self = (ViewController *)context;


    //[self.tb beginUpdates];
    NSMutableArray *iPath=[[NSMutableArray alloc] init];

    for (int i=0; i<[listEntries count]; i++) {
        NSIndexPath *iP=[NSIndexPath indexPathForRow:i inSection:0];
        [iPath addObject:iP];
    }



}

}

The code work fine eccept when in the didreceiveStart callback at the event end I decide to reload data of my table view.
I don’t know why I can’t use in that point self.tableview reload data
Can someone help me?
Thank’s

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tb dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault    reuseIdentifier:CellIdentifier] autorelease];
}

@try {
    cell.textLabel.text=[listEntries objectAtIndex:indexPath.row];
}
@catch (NSException *exception) {
    NSLog(@"%@",exception.reason);
}
@finally {
    NSLog(@"%@",cell.textLabel.text);

}

cell.textLabel.textColor=[UIColor blackColor];

CGFloat r=255;
CGFloat g=140;
CGFloat b=0;


cell.backgroundColor=[UIColor colorWithRed:r green:g blue:b alpha:1.0];
return cell;

}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

NSLog(@"%d",[listEntries count]);
return [listEntries count];
}
  • 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-05-29T19:46:11+00:00Added an answer on May 29, 2026 at 7:46 pm

    In this case, your network event callbacks will be received asynchronously. So, on that thread – which is different to the main thread – you can’t call [self.tableview reloadData] directly.

    If you do, although the reloadData will probably be executed, it’s unpredictable when.

    The golden rule is that any UI operation – or in this cased UI related operation, i.e. a method that somewhere else has UI related code – must be done on the main thread.

    The solution therefore is that you need to do this:

        [self.tableView performSelectorOnMainThread:@selector(reloadData) withObject:nil waitUntilDone:NO];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am relatively new to Objective C/iOS development so I realize that this may
I am new to iOS and Objective-C, I already know that in a class,
I am new to iOS/objective-C and I wanted to know how to build custom
I'm new to iOS and objective-C. Before I dive down into this I'd like
I'm new to iOS and Objective-C. I have an application that displays a table
I need to write a iOS Objective-C app that supports Themes. The idea is
New to iOS/Objective-C here. I've spent a lot of time trying to figure this
I'm new to objective-c and ios, but I'm coming along alright. Now I've run
I am very new at iOS and objective-c development, so I am struggling with
I am new in ios development .Now i am trying to develop an ipad

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.