refreshing contents of UITextView - uitextview

I have a textview which contains chat history obtained from a server.The chat history is being constantly updated through a thread which I had started in a previous view. My problem is how do I constantly update my UITextView to reflect the changes?
self.textView.text = [[NSString alloc]initWithFormat:#"%#",chatHistory];

I use something like this:
NSString *newMessage = [NSString stringWithFormat:#"%#\n%#", [textView text], newChat];
[textView setText:newMessage];
also make sure your GUI updates are on the main application thread.
[self performSelectorOnMainThread:#selector(updateMyGui) withObject:nil waitUntilDone:NO];

Related

How to change viewcontroller on buttonTapped with iCarousel?

I have a viewcontroller with an iCarousel.
When I tap on an item that I know how to display an UIalert but, now I want to change view controller to go on an other already created viewcontroller
I'm guessing you need something like this:
MyOtherViewControllersName *vc =[[MyOtherViewControllersName alloc]initWithNibName:#"MyOtherViewControllersName" bundle:nil];
[self presentModalViewController:vc animated:YES];
Just put it in the same method where you're generating the alert message.

Adding UINavigationController to xCode Tab Bar Application Template

How to add UINavigationController to xCode Tab Bar Application Delegate?
My structure is based on xCode Tab Bar Application Delegate, with 2 tabs, First View & Second View respectively. For First View, I added a UITableView. I just want to make use of UINavigationController function [self.navigationController pushViewController:animated:] to push a subview and allow a navigation bar to be shown in subview. After pushing the subview, the tab bar must still be there.
Sounds simple, but I have no idea how to achieve it. Please help.
I started with a Window-based template instead and did this to achieve the same thing.
I created my NavigationControllers and TabBarController in my app delegate manually.
In your:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Add this:
//Seeting up the Navigation controllers and pushing our TableView controllers.
UINavigationController *unvc1 = [[UINavigationController alloc] init];
UINavigationController *unvc2 = [[UINavigationController alloc] init];
[unvc1 pushViewController:someViewController1 animated:NO];
[unvc2 pushViewController:someViewController2 animated:NO];
[someViewController1 release];[someViewController2 release];//Releasing our TableView controllers.
//Setting up the TabBar controller and pushing our Navigation controllers.
UITabBarController *tbvc = [[UITabBarController alloc] init];
tbvc.viewControllers = [NSArray arrayWithObjects:unvc1, unvc2, nil];
[unvc1 release];[unvc2 release]; //releasing our Navigation controllers.
I hope this helps.
I did this using presentModalViewController:animated . I added tabBar Controller in the modalView. In the method didSelectRowAtIndexPath use this presentModalViewController:animated .I might not be perfect but I had the same problem, but now my app works as I need.

To Use NavigationViewController or NOT

I am creating an application which displays map using MKMapView control. I have a button on the map that takes me to different view (information view) using the following code:
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
self.view = infoViewController.view;
Now after going to the information view I want to go back again to the main view which displays the map without having to loose anything. Is NagivationControlller my best option to use in this scenario?
Try this,
InfoViewController *infoViewController = [[InfoViewController alloc] initWithJogInfo:jogInfo];
[self.navigationController pushViewController:infoViewController animated:YES];
[infoViewController release];
once you push viewController back button is available to come back to rootViewController.

has Presenting modal view controller in iOS 4.3 for iPad changed?

Has Presenting modal view controller in iOS 4.3 for iPad changed?
I created a new view application, then created a new UIViewControllerSubclass called "One", I then changed the background of One.xib to black, in the applications view controller's viewDidLoad method I placed in the code below. I ran the project in the simulator and receive the log that the "Code has run..."
The project can be downloaded from here....Download Source Code of Project
#import "One.h"
- (void)viewDidLoad
{
One *newItemViewController = [[One alloc] initWithNibName:#"One" bundle:nil];
newItemViewController.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentModalViewController:newItemViewController animated:YES];
[newItemViewController release];
NSLog(#"Code has run...");
}
Try putting your this in the viewDidAppear method instead of viewDidLoad.

SearchDisplayController & Coredata Search locks the application while loading, what can i do?

I am building an application with coredata. Its nearly finished but i have a problem.
I want to put a search section on my application. I did it now and it is working, but there is something weird and i could not solve.
When clicked on the search button, i am preparing my Predicates and search my database, and show the data on tableview.
There are about 18000 entries on my database and when searching some words, the application is getting locked for a while, after the proccess end application shows my tableview as i want.
I want to put an activity indicator or something like that while this long progress is being done but i cant, because the application is being locked in that time.
What can i do in this case? I could not find any solution.
Thanks for your helps.
Regards.
you should start search in a new thread. while the main thread will show your indicator view (you can do visual stuff only in a main thread).
//make UIIndicatorView visible and start a new thread
[NSThread detachNewThreadSelector:#selector(doSearch) toTarget:self withObject:nil];
-(void) doSearch{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
//do search stuff;
....
// tell your main thread that search is done
[self performSelectorOnMainThread:#selector(searchDone) withObject:nil waitUntilDone:NO];
[pool release]; }
-(void) searchDone{ //hide UIIndicator view
}

Resources