App crashed when trying to change UITextView.text - objective-c

My app crashed when i trying to change UITextView text.
Here is the code: (header file):
//
#import <UIKit/UIKit.h>
#interface DetailViewController : UIViewController {
IBOutlet UIImageView *appImage;
IBOutlet UILabel *appName;
IBOutlet UILabel *appDeveloper;
IBOutlet UILabel *appVersion;
UIActivityIndicatorView *loading;
IBOutlet UITextView *appAbout;
NSString *selectedApp;
}
#property (nonatomic, retain) NSString *selectedApp;
#property (nonatomic, retain) IBOutlet UIImageView *appImage;
#property (nonatomic, retain) IBOutlet UILabel *appName;
#property (nonatomic, retain) IBOutlet UILabel *appDeveloper;
#property (nonatomic, retain) IBOutlet UILabel *appVersion;
#property (nonatomic, retain) UIActivityIndicatorView *loading;
#property (nonatomic, retain) UITextView *appAbout;
#end
implementation file:
- (void)loadData {
NSString *trimmedString = [selectedApp stringByReplacingOccurrencesOfString:#" " withString:#"%20"];
self.navigationItem.title = #"Info";
NSLog(#"%#", trimmedString);
NSString *website = [NSString stringWithFormat:#"http://shaymargolisapps.x10.mx/send.php?mission=GetNameOfApps&aname=%#", trimmedString];
NSData *dataURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:website]];
NSString *strResult = [[[NSString alloc] initWithData:dataURL encoding:NSUTF8StringEncoding]autorelease];
appName.text = strResult;
NSString *website1 = [NSString stringWithFormat:#"http://shaymargolisapps.x10.mx/send.php?mission=GetDeveloperOfApp&aname=%#", trimmedString];
NSData *dataURL1 = [NSData dataWithContentsOfURL:[NSURL URLWithString:website1]];
NSString *strResult1 = [[[NSString alloc] initWithData:dataURL1 encoding:NSUTF8StringEncoding]autorelease];
appDeveloper.text = strResult1;
NSString *website2 = [NSString stringWithFormat:#"http://shaymargolisapps.x10.mx/send.php?mission=GetVersionOfApp&aname=%#", trimmedString];
NSData *dataURL2 = [NSData dataWithContentsOfURL:[NSURL URLWithString:website2]];
NSString *strResult2 = [[[NSString alloc] initWithData:dataURL2 encoding:NSUTF8StringEncoding]autorelease];
appVersion.text = strResult2;
NSString *website3 = [NSString stringWithFormat:#"http://shaymargolisapps.x10.mx/send.php?mission=GetInfoOfApp&aname=%#", trimmedString];
NSData *dataURL3 = [NSData dataWithContentsOfURL:[NSURL URLWithString:website3]];
NSString *strResult3 = [[[NSString alloc] initWithData:dataURL3 encoding:NSUTF8StringEncoding]autorelease];
NSLog(#"%#", strResult3);
**appAbout.text = strResult3;**
NSString *website4 = [NSString stringWithFormat:#"http://shaymargolisapps.x10.mx/send.php?mission=GetImageOfApp&aname=%#", trimmedString];
NSData *dataURL4 = [NSData dataWithContentsOfURL:[NSURL URLWithString:website4]];
NSString *strResult4 = [[[NSString alloc] initWithData:dataURL4 encoding:NSUTF8StringEncoding]autorelease];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strResult4]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
[appImage setImage:image];
[image release];
[imageData release];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[loading stopAnimating];
[loading setHidden:YES];
[appName setHidden:NO];
[appDeveloper setHidden:NO];
[appVersion setHidden:NO];
[appImage setHidden:NO];
[appAbout setHidden:NO];
}
My app crashed on appAbout.text = strResult3; line. What am I doing wrong?
loadData is called with [self performSelectorInBackground:#selector(loadData) withObject:nil]; from viewDidLoad
(Xcode 4.4 DP2, iPhone Simulator 5.1, base SDK 4.3)

You must not change UI* objects from a background thread. That has to be done from the main thread.
You could use gcd to perform the changes on the main thread. Something like this:
/* ... */
NSString *strResult4 = [[[NSString alloc] initWithData:dataURL4 encoding:NSUTF8StringEncoding]autorelease];
NSData* imageData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:strResult4]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
self.navigationItem.title = #"Info";
appName.text = strResult;
appDeveloper.text = strResult1;
appVersion.text = strResult2;
appAbout.text = strResult3;
[appImage setImage:image];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[loading stopAnimating];
[loading setHidden:YES];
[appName setHidden:NO];
[appDeveloper setHidden:NO];
[appVersion setHidden:NO];
[appImage setHidden:NO];
[appAbout setHidden:NO];
});
[image release];
[imageData release];

Related

MKMapView pin animation and annotation

I'm using the google places API to find some restaurants nearby (based on current location using core location manager); currently, I'm able to drop pins. I use the searchBarSearchButtonClicked method, and inside of a dispatch_async block, I call my method to parse through my serialized data and attribute values to properties of my pin class (class MKAnnotation). I'd like to animate my pin drops, and also actually display annotations...for some reason I had them working before but now they won't show up when I click on the pins.
VIEW CONTROLLER.H
#interface MyViewController : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate, UISearchBarDelegate,NSURLSessionDelegate> {
CLLocationManager *locationManager;
}
#property (strong, nonatomic) MKMapView *mapView;
#property (strong, nonatomic) UISearchBar *searchBar;
#property (strong, nonatomic) UIImageView *logo;
#property (strong, nonatomic) UIToolbar *toolBar;
#property (strong, nonatomic) NSString *places;
#end
VIEW CONTROLLER.M
-(void)searchBarSearchButtonClicked:(UISearchBar *)searchBar {
NSLog(#"%#", self.searchBar.text);
NSURLSession *session = [NSURLSession sharedSession];
NSString *s = [NSString
stringWithFormat:#"https://maps.googleapis.com/maps/api/place/nearbysearch/json?keyword=%#&location=%f,%f&radius=5&types=food&key=AIzaSyCg6Ahz_hQ1f2rjKEAWcJKQetblPVjHS-E", self.searchBar.text, locationManager.location.coordinate.latitude, locationManager.location.coordinate.longitude];
NSURL *url = [[NSURL alloc]initWithString:s];
NSURLRequest *request = [[NSURLRequest alloc]initWithURL:url];
NSURLSessionDownloadTask *task = [session downloadTaskWithRequest:request completionHandler:^(NSURL *location, NSURLResponse *response, NSError *error) {
NSData *dataResponse = [[NSData alloc]initWithContentsOfURL:location];
NSDictionary *dictionaryReponse = [NSJSONSerialization JSONObjectWithData:dataResponse options:kNilOptions error:&error];
NSMutableArray *finalResults = [dictionaryReponse objectForKey:#"results"];
dispatch_async(dispatch_get_main_queue(), ^{
[self placeAnnotations:finalResults];
});
}];
[task resume];
}
-(void)placeAnnotations:(NSMutableArray *)data {
for (id<MKAnnotation> annotation in self.mapView.annotations) {
// if ([annotation isKindOfClass:[MapPoint class]]) {
[self.mapView removeAnnotation:annotation];
// }
}
for (int i = 0; i < [data count]; i++) {
NSDictionary *place = [data objectAtIndex:i];
NSDictionary *geo = [place objectForKey:#"geometry"];
NSDictionary *location = [geo objectForKey:#"location"];
NSString *name = [place objectForKey:#"name"];
NSString *vicinity = [place objectForKey:#"vicinity"];
CLLocationCoordinate2D placeCoord;
placeCoord.latitude = [[location objectForKey:#"lat"] doubleValue];
placeCoord.longitude = [[location objectForKey:#"lng"] doubleValue];
MapPoint *newPin = [MapPoint new];
newPin.name = name;
newPin.address = vicinity;
newPin.coordinate = placeCoord;
MKPinAnnotationView *newAnnotation = [[MKPinAnnotationView alloc]initWithAnnotation:newPin reuseIdentifier:#"annotation"];
newAnnotation.animatesDrop = YES;
[self.mapView addAnnotation:newPin];
}
[self.mapView reloadInputViews];
}
I

json photo path xcode

i can't get my photo in json, did i haven't something wrong to get that? i already check my photo url in php,it works,
in my tableview.m file:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
DetailHomeViewController * dvc = [[DetailHomeViewController alloc]init];
HomeDetail * currentHome = [HomeArray objectAtIndex:indexPath.row];
dvc.photodetail = currentHome.photo_path;
NSURL *url = [NSURL URLWithString:dvc.photodetail];
NSData *data = [NSData dataWithContentsOfURL:url];
dvc.photolabel.image = [UIImage imageWithData:data];
[self presentViewController:dvc animated:YES completion:nil];
}
#pragma mark - Methods
- (void) retrieveData
{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
NSURL * url = [NSURL URLWithString:getDataURL];
NSData * data = [NSData dataWithContentsOfURL:url];
json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
HomeArray = [[NSMutableArray alloc]init];
for (int i = 0; i < json.count; i++)
{
NSString * photo = [[json objectAtIndex:i] objectForKey:#"photo_path"];
HomeDetail * home2 = [[HomeDetail alloc]initWithPhoto_path:photo];
[HomeArray addObject:home2];
}
[self.myTableView reloadData];
}
my HomeDetail.h file:(Json file)
#property (nonatomic, strong) NSString * photo_path;
//Methods
- (id) initWithPhoto_path: (NSString *) photo ;
my HomeDetail.m file:
- (id) initWithPhoto_path: (NSString *) photo ;
{
self = [super init];
if (self)
{photo_path = photo;}
return self;
}
my DetailHomeViewController.h file:
#property (nonatomic, strong) NSString * photodetail;
#property (strong, nonatomic) IBOutlet UIImageView *photolabel;
my DetailHomeViewController.m file:
- (void)viewDidLoad
{
[super viewDidLoad];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:NO];
// photolabel.image = photodetail;
NSURL *url = [NSURL URLWithString:photodetail];
NSData *data = [NSData dataWithContentsOfURL:url];
photolabel.image = [UIImage imageWithData:data];
}
and here is my json data:
[{"id":"2","detail_english":" TESTING_DETAIL","photo_path":"img\/uploads\/news\/news_20150320075842.png","date":"2013-10-15"‌​,"display_stat":"1","news_order":"1"},
{"id":"5","detail_english":"empty","photo_path":"img\/uploads\/news\/news_20150323105547.png","date":"2015-03-20","display_stat":"1","news_order":"1"}]
Your photo path is not a full url, you need to append the domain name.
So you string would look like this:
http://www.domain.com/img/uploads/news/news_20150323105547.png

AVAssetWriter is always on AVAssetWriterStatusFailed status

my goal is to apply some filters on the camera input in real time. To do that step by step, I'm trying to get the input form the camera with AVFoundation record a video and save it in the camera roll. I tried, but for some reason the AVAssetWriter is always in AVAssetWriterStatusFailed and so the appendSampleBuffer: method always failed. Where is my error? Someone can help me?
Thanks!
ViewController.h
#import <UIKit/UIKit.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <AVFoundation/AVFoundation.h>
#interface ViewController : UIViewController <AVCaptureVideoDataOutputSampleBufferDelegate>
#property (weak, nonatomic) IBOutlet UIImageView *imageView;
#property (weak, nonatomic) IBOutlet UIButton *startRecButton;
#property (weak, nonatomic) IBOutlet UIButton *stopRecButton;
#property (weak, nonatomic) IBOutlet UIButton *startVideocamera;
- (IBAction)startRecordingButtonPressed:(UIButton *)sender;
- (IBAction)stopRecordingButtonPressed:(UIButton *)sender;
- (IBAction)startVideocameraButtonPressed:(UIButton *)sender;
#end
ViewController.m
#import "ViewController.h"
#interface ViewController ()
#property (strong, nonatomic) AVAssetWriter* videoAssetWriter;
#property (strong, nonatomic) AVAssetWriterInput* videoAssetWriterInput;
#property (strong, nonatomic) NSURL* temporaryVideoURL;
#end
#implementation ViewController
#pragma mark - Variables
#synthesize imageView;
#synthesize videoAssetWriter;
#synthesize videoAssetWriterInput;
#synthesize temporaryVideoURL;
//initCaptureSession Method
AVCaptureSession* captureSession;
AVCaptureDevice* videoCaptureDevice;
AVCaptureDeviceInput* videoCaptureDeviceInput;
AVCaptureVideoDataOutput* videoDataOutput;
dispatch_queue_t videoQueue;
//captureOutput:didOutputSampleBuffer Method
CMSampleBufferRef currentSampleBuffer;
BOOL isRecording;
//newPixelBufferFromCGImage Method
CGAffineTransform frameTransform;
CGSize frameSize;
#pragma mark - User Interface
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)startRecordingButtonPressed:(UIButton *)sender {
[self initWriter];
}
- (IBAction)stopRecordingButtonPressed:(UIButton *)sender {
[self stopWriter];
}
- (IBAction)startVideocameraButtonPressed:(UIButton *)sender {
[self initCaptureSession];
}
#pragma mark - Capture Utils
-(void) initCaptureSession{
captureSession = [[AVCaptureSession alloc] init];
[captureSession setSessionPreset:AVCaptureSessionPreset1280x720];
videoCaptureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
NSError* error;
videoCaptureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:videoCaptureDevice error:&error];
if([captureSession canAddInput:videoCaptureDeviceInput]){
[captureSession addInput:videoCaptureDeviceInput];
}
videoDataOutput = [[AVCaptureVideoDataOutput alloc]init];
[captureSession addOutput:videoDataOutput];
videoQueue = dispatch_queue_create("videoQueue", NULL);
[videoDataOutput setAlwaysDiscardsLateVideoFrames:NO];
[videoDataOutput setSampleBufferDelegate:self queue:videoQueue];
NSString* key = (NSString*)kCVPixelBufferPixelFormatTypeKey;
NSNumber* value = [NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA];
NSDictionary* videoSettings = [NSDictionary dictionaryWithObject:value forKey:key];
[videoDataOutput setVideoSettings:videoSettings];
[captureSession startRunning];
}
-(void) captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer: (CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
currentSampleBuffer = sampleBuffer;
CGImageRef image = [self imageFromSampleBuffer:currentSampleBuffer];
dispatch_sync(dispatch_get_main_queue(),
^{
if(!isRecording){
imageView.image = [UIImage imageWithCGImage: image scale:1.0 orientation:UIImageOrientationRight];
}
else{
imageView.image = [UIImage imageWithCGImage: image scale:1.0 orientation:UIImageOrientationRight];
// [videoAssetWriterInput appendSampleBuffer:currentSampleBuffer];
if (![videoAssetWriterInput appendSampleBuffer:sampleBuffer]) {
[self showError:[videoAssetWriter error]];
}
NSLog(#"%ld", (long)[videoAssetWriter status]);
}
});
CGImageRelease(image);
}
-(void)captureOutput:(AVCaptureOutput *)captureOutput didDropSampleBuffer: (CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection{
NSLog(#"didDropSampleBuffer CALLED");
}
#pragma mark - Writer Utils
-(void) initWriter{
temporaryVideoURL = [NSURL fileURLWithPath:[NSString stringWithFormat:#"%#%#", NSTemporaryDirectory(), #"Movie.MOV"]];
NSLog(#"%#", temporaryVideoURL);
NSError* error;
videoAssetWriter = [[AVAssetWriter alloc] initWithURL:temporaryVideoURL fileType:AVFileTypeQuickTimeMovie error:&error];
NSParameterAssert(videoAssetWriter);
NSLog(#"%ld", (long)[videoAssetWriter status]);
NSDictionary *videoSettings = [NSDictionary dictionaryWithObjectsAndKeys:
AVVideoCodecH264, AVVideoCodecKey,
[NSNumber numberWithInt:1280], AVVideoWidthKey,
[NSNumber numberWithInt:720], AVVideoHeightKey,
nil];
videoAssetWriterInput = [AVAssetWriterInput assetWriterInputWithMediaType:AVMediaTypeVideo outputSettings:videoSettings];
NSParameterAssert(videoAssetWriterInput);
NSLog(#"%ld", (long)[videoAssetWriter status]);
if([videoAssetWriter canAddInput:videoAssetWriterInput]){
[videoAssetWriter addInput:videoAssetWriterInput];
}
isRecording = YES;
[videoAssetWriter startWriting];
NSLog(#"%ld", (long)[videoAssetWriter status]);
}
-(void) stopWriter{
[videoAssetWriterInput markAsFinished];
[videoAssetWriter finishWritingWithCompletionHandler:^{
NSLog(#"finishWritingWithCompletionHandler CALLED");
isRecording = NO;
[self saveVideoToCameraRoll];
videoAssetWriter =nil;
videoAssetWriterInput= nil;
}];
// [videoAssetWriter finishWriting];
// isRecording = NO;
// [self saveVideoToCameraRoll];
}
-(void) saveVideoToCameraRoll{
ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init];
[library writeVideoAtPathToSavedPhotosAlbum:temporaryVideoURL completionBlock:^(NSURL *assetURL, NSError *error){
NSLog(#"ASSET URL: %#", [assetURL path]);
if(error) {
NSLog(#"CameraViewController: Error on saving movie : %# {imagePickerController}", error);
}
else {
NSLog(#"Video salvato correttamente in URL: %#", assetURL);
BOOL fileExists = [[NSFileManager defaultManager] fileExistsAtPath:[temporaryVideoURL path]];
NSLog(#"IL FILE ESISTE: %hhd", fileExists);
NSLog(#"E PESA: %#", [[[NSFileManager defaultManager] attributesOfItemAtPath: [temporaryVideoURL path] error:&error] objectForKey:NSFileSize]);
}
}];
}
This error is because of a reason that a file with similar filename already exist.
In my case, I was using a static file name for testing purpose, which caused the error. Making it something unique something like:
"\(Date().timeIntervalSince1970).mp4" fixed it.

Login to web services

I am currently stuck on the part where user use his username and password to view his data. I did try every piece of information on this website to find out how to make it work with no luck so far if anyone can point me in the right direction I'll be grateful.
here is my .h file:
#import <UIKit/UIKit.h>
#interface ePaymentLoginViewController : UIViewController {
IBOutlet UITextField *__weak usernameField;
IBOutlet UITextField *__weak passwordField;
IBOutlet UIButton *__weak loginButton;
IBOutlet UIActivityIndicatorView *__weak loginIndicator;
}
#property (weak, nonatomic) UITextField *usernameField;
#property (weak, nonatomic) UITextField *passwordField;
#property (weak, nonatomic) UIButton *loginButton;
#property (weak, nonatomic) UIActivityIndicatorView *loginIndicator;
- (IBAction) login: (id) sender;
- (IBAction)backButton:(id)sender;
- (IBAction)cancelButton:(id)sender;
#end
here is my .m file:
#import "ePaymentLoginViewController.h"
#interface ePaymentLoginViewController ()
#end
#implementation ePaymentLoginViewController
#synthesize usernameField;
#synthesize passwordField;
#synthesize loginButton;
#synthesize loginIndicator;
- (IBAction) login: (id) sender
{
NSString *post =[NSString stringWithFormat:#"%#/%#",usernameField.text, passwordField.text];
NSString *hostStr = #"http://ourserver/mobilepay/MobilePayService.svc/verify/%#/%#";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:#"text/json"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:#"Congrats" message:#"You are authorized" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertsuccess show];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:#"Login Failed" message:#"Username or Password Incorrect" delegate:self cancelButtonTitle:#"Ok" otherButtonTitles:nil, nil];
[alertsuccess show];
loginIndicator.hidden = TRUE;
loginButton.enabled = TRUE;
[loginIndicator startAnimating];
}
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn’t have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren’t in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
-(IBAction)backButton:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
-(IBAction)cancelButton:(id)sender{
[self dismissViewControllerAnimated:YES completion:nil];
}
#end
after successful login this is how the url should look and it will send JSON data
http://ourserver/mobilepay/MobilePayService.svc/verify/user123/test123
{
"Table": [
{
"comp_filenum": 1006842,
"comp_namar": "username123",
"comp_civid": "100000"
}
],
"Table1": [
{
"tran_num": 30301,
"inst_val": 1725,
"balance": 3450,
"late_amount": 3450,
"late_inst_no": 2,
"legal_status": 0,
"baloon_balance": 0,
"late_bal_no": 0,
"remain_bal_no": 0,
"clienttype": 2,
"filenumber": 1006842,
"customername": "username123",
"civilid": "100000",
"saleprice": 82800,
"costprice": 66005,
"last_receiptnumber": "e22512",
"last_paydate": "2012-05-02T00:00:00",
"last_payamount": 1725,
"paidamount": 79350,
"remaininginstallment": 16
},
So what am i doing wrong at this point and what is the right way to do it.
Try with below line :
NSString *hostStr = [NSString stringWithFormat:#"http://ourserver/mobilepay/MobilePayService.svc/verify/%#/%#",usernameField.text, passwordField.text];
NSURL *aURL = [NSURL URLWithString: hostStr];
NSLog(#"%#",aURL); // check the log
NSData *dataURL = [NSData dataWithContentsOfURL:aURL];
Try to show the value of hostStr
NSString *post =[NSString stringWithFormat:#"%#/%#",usernameField.text, passwordField.text];
NSString *hostStr = #"http://ourserver/mobilepay/MobilePayService.svc/verify/%#/%#";
hostStr = [hostStr stringByAppendingString:post];
It will show :
http://ourserver/mobilepay/MobilePayService.svc/verify/%#/%#username/password
Try with this :
NSString *hostStr = #"http://ourserver/mobilepay/MobilePayService.svc/verify/%#/%#";
NSString *url = [NSString stringWithFormat:hostStr,usernameField.text, passwordField.text];

Having one method to save entered text into a string and bring up a uiaction sheet which will then alter the string depending on what button is chosen

I have a method that should save what is entered into the text field as a string (later to be saved into a NSMutableArray) and then bring up an action sheet after the textfield is exited that will specify the string further depending on which button is clicked. Please help! I'm in high school attempting to write a program for my senior project so any help is MUCH appreciated! Thanks!
#implementation EnteringCoursesViewController
#synthesize classField;
#synthesize indicatedClass;
#synthesize labelClassTitle;
#synthesize selectRotationController;
#synthesize classesEnteredTable;
- (IBAction)classFieldDoneEditing:(id)sender
withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
self.indicatedClass = classField.text;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%#", indicatedClass];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[sender resignFirstResponder];
typeSheet = [[UIActionSheet alloc]
initWithTitle:#"Class types"delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:#"Core Class", #"Elective", nil];
[typeSheet showInView:self.view];
[typeSheet release];
if (buttonIndex == 0) {
self.indicatedClass = classField.text;
NSString *indicatedString = indicatedClass;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%# meets 6 times per rotation", indicatedString];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[indicatedClass release];
}
else if (buttonIndex == 1) {
self.indicatedClass = classField.text;
NSString *indicatedString = indicatedClass;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%# meets 3 times per rotation", indicatedString];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[indicatedClass release];
}
}
Comments on just the theoretical approach are helpful, but since I'm so new to this I'd love specific coding thanks.
#interface EnteringCoursesViewController : UIViewController {
UILabel *labelClassTitle;
NSString *indicatedClass;
UITextField *classField;
UIViewController *selectRotationController;
UITableView *classesEnteredTable;
}
#property (nonatomic, retain) IBOutlet UILabel *labelClassTitle;
#property (nonatomic, copy) NSString *indicatedClass;
#property (nonatomic, retain) IBOutlet UITextField *classField;
#property (nonatomic, retain) UIViewController *selectRotationController;
#property (nonatomic, retain) IBOutlet UITableView *classesEnteredTable;
- (IBAction)chooseFirstMeeting:(id)sender;
- (IBAction)classFieldDoneEditing:(id)sender withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex;
You can migrate the to methods into one by adding multiple arguments to your action that is hooked up with the button. The code should be something like this:
- (IBAction)cassFieldDoneEditing:(id)sender
withActionSheet:(UIActionSheet *)typeSheet
clickedButtonAtIndex:(NSInteger)buttonIndex
{
self.indicatedClass = classField.text;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%#", indicatedClass];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[sender resignFirstResponder];
UIActionSheet *typeSheet = [[UIActionSheet alloc]
initWithTitle:#"Class types"delegate:self
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:#"Core Class", #"Elective", nil];
[typeSheet showInView:self.view];
[typeSheet release];
if (buttonIndex == 0) {
self.indicatedClass = classField.text;
NSString *indicatedString = indicatedClass;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%# meets 6 times per rotation", indicatedString];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[indicatedClass release];
}
else if (buttonIndex == 1) {
self.indicatedClass = classField.text;
NSString *indicatedString = indicatedClass;
NSString *greeting = [[NSString alloc]
initWithFormat:#"%# meets 3 times per rotation", indicatedString];
labelClassTitle.text = greeting;
labelClassTitle.hidden = NO;
[greeting release];
[indicatedClass release];
}
[theSmallArray addObject:indicatedClass];
}
As I haven't tested the code, there may be errors. Just report back if you got any problems alright?