Search Results

Search found 451 results on 19 pages for 'nsbundle'.

Page 15/19 | < Previous Page | 11 12 13 14 15 16 17 18 19  | Next Page >

  • How to fix a slow scrolling table view

    - by hanumanDev
    I have a table view that's scrolling slowly. Does anyone know why that might be? There is an image for each row, but even after the images are loaded it still stutters and scrolls slowly. thanks for any help here's my code: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *simpleTableIdentifier = @"SimpleTableCell"; SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil]; cell = [nib objectAtIndex:0]; } // Get item from tableData NSDictionary *item = (NSDictionary *)[displayItems objectAtIndex:indexPath.row]; // display the youdeal deal image photoString = [item objectForKey:@"image"]; UIImage *image = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:photoString]]]; cell.titleLabel.text = [item objectForKey:@"supercat"]; cell.descriptionLabel.text = [item objectForKey:@"title"]; NSString *convertedLeftCount = [NSString stringWithFormat:@"%@",[item objectForKey:@"left_count"]]; cell.amountLabel.text = convertedLeftCount; cell.thumbnailImageView.image = image; cell.priceLabel.text = [item objectForKey:@"cat"]; return cell; }

    Read the article

  • UIImageView and UIScrollView load lot of pictures

    - by Allan.Chen
    In my app, i use UIImageView and UIScrollView to show lot of pictures(Every time there are about 20 pictures and every pictures about 600px*500px and size is about 600KB ), i use for this code to do this function. Here is code: //Here is pictures Data; self.klpArry = self.pictureData; CGSize size = self.klpScrollView1.frame.size; for (int i=0; i < [klpArr count]; i++) { UIImageView *iv = [[UIImageView alloc] initWithFrame:CGRectMake((size.width * i)+300, 20, 546, 546)]; NSString *filePath = [[NSBundle mainBundle] pathForResource:[klpArr objectAtIndex:i] ofType:@"jpg"]; UIImage *imageData = [[UIImage alloc]initWithData:[NSData dataWithContentsOfFile:filePath]]; [iv setImage:imageData]; iv.backgroundColor = [UIColor grayColor]; [self.klpScrollView1 addSubview:iv]; imageData = nil; iv = nil; iv.image = nil; filePath = nil; [imageData release]; [filePath release]; [iv release]; } // show the picture in scrollview; [self.klpScrollView1 setContentSize:CGSizeMake(size.width * numImage, size.height)]; self.klpScrollView1.pagingEnabled = YES; self.klpScrollView1.showsHorizontalScrollIndicator = NO; self.klpScrollView1.backgroundColor = [UIColor grayColor]; But everytime i init this function, the memory will increase about 5MB, Actually i release UIImageView, UIimage and UIScrollView (vi.image=nil,[vi release]) but i doesn't work, it can't release the memory. BTW, i use my friend code first vi.image=nil then vi=nil; but the pictures not to show on scrollview. any one can help me ?? Thx ~~

    Read the article

  • Iphone: XML image problem

    - by avanadra
    Hi! I have a question about parsing XML and putting it into a table. I parsed the following elements from a RSS feed : title, dc:creator and enclosure url (= an image). The parsing is working, i can see everything showing up in the console. But when i try to load everything into the tablecell, everything shows up except for the image. So i figured that the problem must be in the CellForRowatIndexPath method in the RootViewController.m ( or in the TableCell.m) What am i doing wrong? Please help! Ive been struggling for days with this and just cant seem to figure it out! Heres the CellForRowatIndexPath: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; WerkTableCell *cell = (WerkTableCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"WerkCell" owner:self options:nil]; cell =self.werkCell; } // Configure the cell. NSMutableArray *cont= [xmlcont items];// is niet in tablevb v. PS ItemData *current =[cont objectAtIndex:indexPath.row]; cell.titelLabel.text = [current titel]; cell.makerLabel.text = [current maker]; cell.thumbImage.image = [UIImage imageNamed:[current image]]; return cell; }

    Read the article

  • iPhone and iPad : Doing a "select * from something" query in a SQLite database

    - by Abramodj
    Hi folks, i'm trying to use the SQLite data base in my iPad app, and here's my function to make a query: - (void)executeQuery:(char*)query { NSString *file = [self getWritableDBPath]; NSFileManager *fileManager = [NSFileManager defaultManager]; BOOL success = [fileManager fileExistsAtPath:file]; // If its not a local copy set it to the bundle copy if(!success) { //file = [[NSBundle mainBundle] pathForResource:DATABASE_TITLE ofType:@"db"]; [self createEditableCopyOfDatabaseIfNeeded]; } dataArray = NULL; dataArray = [NSMutableArray array]; sqlite3 *database = NULL; if (sqlite3_open([file UTF8String], &database) == SQLITE_OK) { sqlite3_exec(database, query, loadTimesCallback, dataArray, NULL); } sqlite3_close(database); [self logResults]; } if I call [self executeQuery:"select name from table1"]; everything is working fine. But if i call [self executeQuery:"select * from cars"]; the app crashes telling me that the NSMutableArray dataArray is not the right kind of variable where to set the query results. So, how can i do a "select * form table1" query, and store the results? Thanks! EDIT: Here's my loadTimesCallback method: static int loadTimesCallback(void *context, int count, char **values, char **columns) { NSMutableArray *times = (NSMutableArray *)context; for (int i=0; i < count; i++) { const char *nameCString = values[i]; [times addObject:[NSString stringWithUTF8String:nameCString]]; } return SQLITE_OK; }

    Read the article

  • ipad subview not loading before code is executing

    - by ethan Criss
    I have a command that should be loading a subview before a particular piece of time intensive code executes. However the command runs, the timely code executes and then the subview shows up. Is there anything I can do to fix this problem? progressViewController = [[ProgressView alloc] initWithNibName:@"ProgressView" bundle:[NSBundle mainBundle]]; [self.view addSubview:[progressViewController view]]; NSString *name=@"guy"; NSString *encodedName =[[NSString alloc] init]; int asci; for(int i=0; i < [name length]; i++) { //NSLog(@"1"); asci = [name characterAtIndex:i]; NSString *str = [NSString stringWithFormat:@"%d,", asci]; encodedName =[encodedName stringByAppendingFormat: str]; } NSString *urlString = [NSString stringWithFormat:@"someurl.com"]; NSURL *theUrl = [[NSURL alloc] initWithString:urlString]; NSString *result=[NSString stringWithContentsOfURL:theUrl]; result = [result substringFromIndex:61]; result = [result substringToIndex:[result length] - 20]; NSLog(result); outLab.text=result; [[progressViewController view] removeFromSuperview];

    Read the article

  • EGODatabase does not retain inserted record

    - by user135775
    Hi Guy! I'm using EGODatabase to process my data. When I tried to insert data into the database which I created with Base and attached to the project, the data that was inserted programmatically will not show up when I restart my app.However the data inserted manually using Base will show up just fine. Following is the code for inserting data into the database: NSString *path = [[NSBundle mainBundle] pathForResource:@"Database" ofType:@"db"]; db = [EGODatabase databaseWithPath:path]; if ([db open]) { NSLog(@"Database is opened successfully!"); } else { NSLog(@"Database is failed to open!"); } NSArray *params = [NSArray arrayWithObjects:[aFeed feedID], [aFeed title], nil]; [db executeUpdate:@"Insert INTO Feed (FeedID, Title) VALUES (?, ?)" parameters:params]; EGODatabaseResult *results = [db executeQuery:@"SELECT * FROM Feed"]; for ( EGODatabaseRow * row in results) { NSLog(@"ID: %@ Title: %@", [row stringForColumn:@"FeedID"], [row stringForColumn:@"Title"]); } I appreciate if anyone can share me a working sample code for EGODatabase. I'm using EGODatabase because I might have multi-threading code that write to the database. Thank in advance.

    Read the article

  • Custom Cell over lapping.

    - by user338322
    I am trying to use a custom cell, My custom cell is of size 320*220 pixels. My table size is 320* by 1500 which is large enough I have set custom cell's view in scale to fill mode. But when i fill the table using custom cell all i see is first row. i have total four rows to be filld in a custom way. but they gets overlapped and i can not see any of the table.. They do look, but overlapped, Any hints .. about why its happening Do i need to make changes into nib? -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ static NSString *CellIdentifier = @"CustomCell"; CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil]; for (id oneObject in nib) if ([oneObject isKindOfClass:[CustomCell class]]) cell = (CustomCell *)oneObject; } cell.iconImage.image = [UIImage imageNamed:[NSString stringWithFormat:@"beach%d.jpg",indexPath.row+1]]; cell.title.text=[[RArrray objectAtIndex:indexPath.row] objectForKey:@"Beach"]; return cell; }

    Read the article

  • How to play sound automatically when scrolling to the next page?

    - by viper15
    I'm using Page Control example from Apple. I want to be able to scroll horizontally to certain page and get the sound automatically play when viewing that page? And then sound stop when viewing the other page? So, for example. On page 1, i have some texts. When i go to the next page which is on page 2, i want sound to be automatically play and stop when i go to page 3. I'm planning to use If statements (since it's not that many pages) to determine which page will get the sound. My question is simple. How do you get the sound play automatically when viewing certain page? By the way, I'm planning to use System Sound. I know how to play the sound using button. But how do you get it automatically - start when certain page appear and stop when moving to the next page. Thank you in advance! Edited: I put in this code in ViewDidLoad but the sound played on sooner before it reach the page intended: // Set the label and background color when the view has finished loading. - (void)viewDidLoad { pageNumberLabel.text = [NSString stringWithFormat:@"Page %d", pageNumber + 1]; self.view.backgroundColor = [MyViewController pageControlColorWithIndex:pageNumber]; if (pageNumber == 3) { NSString *path = [[NSBundle mainBundle] pathForResource:@"crunch" ofType:@"wav"]; SystemSoundID soundID; AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:path], &soundID); AudioServicesPlaySystemSound(soundID); } }

    Read the article

  • create CLLocationCoordinate2D from array

    - by shani
    I have a plist with dictionary of array's with coordinates (stored as strings). I want to create a CLLocationCoordinate2D from every array and crate an overlay for the map. I did that - NSString *thePath = [[NSBundle mainBundle] pathForResource:@"Roots" ofType:@"plist"]; NSDictionary *pointsDic = [[NSDictionary alloc] initWithContentsOfFile:thePath]; NSArray *pointsArray = [NSArray arrayWithArray:[pointsDic objectForKey:@"roade1"]]; CLLocationCoordinate2D pointsToUse[256]; for(int i = 0; i < 256; i++) { CGPoint p = CGPointFromString([pointsArray objectAtIndex:i]); pointsToUse[i] = CLLocationCoordinate2DMake(p.x,p.y); NSLog(@"coord %f",pointsToUse [i].longitude); NSLog(@"coord %f",pointsToUse [i].latitude); } MKPolyline *myPolyline = [MKPolyline polylineWithCoordinates:pointsToUse count:256]; [[self mv] addOverlay:myPolyline]; but the app is crashing without any error. (BTW when i remove the addOverLay method the app does not crash). I have 2 questions- What am i doing wrong? I have tried to set the pointsArray count as the argument for the CLLocationCoordinate2D like that - CLLocationCoordinate2D pointsToUse[pointsArray count]; And i am getting an error. How can i set the CLLocationCoordinate2D dynamically ? Thanks for any help. Shani

    Read the article

  • how to slove error when using thread?

    - by ChandreshKanetiya
    I have following error msg in console when using NSThread "Tried to obtain the web lock from a thread other than the main thread or the web thread. This may be a result of calling to UIKit from a secondary thread. Crashing now..." I have submit my sample code here - (void)viewDidLoad { appDeleg = (NewAshley_MedisonAppDelegate *)[[UIApplication sharedApplication] delegate]; [[self tblView1] setRowHeight:80.0]; [super viewDidLoad]; self.title = @"Under Ground"; [UIApplication sharedApplication].networkActivityIndicatorVisible = YES; [NSThread detachNewThreadSelector:@selector(CallParser) toTarget:self withObject:nil]; } -(void)CallParser { Parsing *parsing = [[Parsing alloc] init]; [parsing DownloadAndParseUnderground]; [parsing release]; [self Update_View]; //[myIndicator stopAnimating]; [UIApplication sharedApplication].networkActivityIndicatorVisible = NO; } here "DownloadAndParseUnderground" is the method of downloding data from the rss feed and -(void) Update_View{ [self.tblView1 reloadData]; } when Update_View method is called the tableView reload Data and in the cellForRowAtIndexPath create error and not display custom cell - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"Cell"; CustomTableviewCell *cell = (CustomTableviewCell *) [tblView1 dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { [[NSBundle mainBundle] loadNibNamed:@"customCell" owner:self options:nil]; cell = objCustCell; objCustCell = nil; }

    Read the article

  • Add a smaller subView with new origin

    - by ReachWest
    I can't get my head around this - I know it must be simple.. I'm starting to feel pretty stupid. I have two viewControllers. MainViewController.h/m and LevelsViewController.h/m I want to add a subView from the LevelsViewController class and a view that is built in IB called levelsView. I am calling this from the MainViewController.m file. The levelsView is only 200x200 pixels and I want to offset it from the frame origin of the superView by x=140 pixels and y=50 pixels. I have this working - the view displays, but I can't figure out how to offset it. It only shows up at the 0,0 superView frame origin. (The superView shows below it, which is what I want). Here is the code I call in the method in the MainViewController.m that displays the levelsView.(I have commented out some of the things I have tried - but throws this error: error: request for member 'frame' in 'myLevelsView', which is of non-class type 'LevelsViewController*' ) - (void) displayLevelsPage { if (self.theLevelsView == nil) // Does not yet exist - therefore create { LevelsViewController * myLevelsView = [[LevelsViewController alloc] initWithNibName:@"levelsView" bundle:[NSBundle mainBundle]]; NSLog(@"NEW theLevelsView instance created!"); CGRect frame2 = CGRectMake(140, 50, 200, 200); //myLevelsView.frame = frame2; self.theLevelsView = myLevelsView; [myLevelsView release]; } [self.view addSubview: theLevelsView.view]; NSLog(@"Levels View has been activated"); } Any insight would be appreciated.

    Read the article

  • Paged UIScrollView with UIImageViews only showing first UIImageVIew

    - by Jonathan Brown
    I am working on a paged UIScrollView, but it only wants to show the first UIImageView within it. I add each UIImageView at an offset of the width of the scroll view, so that should create each page. When run, it says the scroll view is the right number of pages, but the images don't show. Any help would be much appreciated! int numSlides = NUM_TUTORIAL_SLIDES; NSString *fileName; UIImageView *slideImageView; CGRect slideFrame; for (int i = 1; i <= numSlides; i++) { slideFrame.origin.x = self.tutorialScrollView.frame.size.width * (i-1); slideFrame.origin.y = 0; slideFrame.size = self.tutorialScrollView.frame.size; slideImageView = [[UIImageView alloc] initWithFrame:slideFrame]; if([[AppManager sharedManager] is4inchScreen]) { fileName = [NSString stringWithFormat:@"Slide%[email protected]", i]; } else { fileName = [NSString stringWithFormat:@"Slide%[email protected]", i]; } slideImageView.image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:fileName ofType:nil]]; [self.tutorialScrollView addSubview:slideImageView]; [slideImageView release]; } self.tutorialScrollView.contentSize = CGSizeMake(self.tutorialScrollView.frame.size.width * numSlides, self.tutorialScrollView.frame.size.height); self.tutorialScrollView.delegate = self;

    Read the article

  • iphone app working on most devices but not a few

    - by Matt Facer
    Hi there. I have recently been rewriting some of my iphone app because a couple of users have said it was crashing on certain events. The event in question is when I add a new XIB to the view using the following code AddItemViewController * add_item = [[AddItemViewController alloc] initWithNibName:@"AddItem" bundle:[NSBundle mainBundle]]; [self presentModalViewController:add_item animated:YES]; [add_item setViewFormat:2]; [add_item release]; it works perfectly on my iphone and a mate's ipod touch (both running 3.1.3) but another user on an ipod touch also with 3.1.3 says it crashes when the function above is called. Why could this be happening? Surely if it works on one device it should work on another?! Is there a better way to add a view which maybe doesnt crash? I have also disabled all the code on the loading xib - so it literally is loading a near blank page. It's SO annoying!! Thanks for any help.

    Read the article

  • objectAtIndex:indexPath.row method always causes exception in IOS

    - by kalkin
    Hi I always seem to get exception when I use objectAtInded method to retrieve NSString from an array. I am reading data from a dictionary which is in the "PropertyList.plist" file.My code is - (void)viewDidLoad { [super viewDidLoad]; NSString *path = [[NSBundle mainBundle] pathForResource:@"PropertyList" ofType:@"plist"]; names = [[NSDictionary alloc] initWithContentsOfFile:path]; keys = [[[names allKeys] sortedArrayUsingSelector: @selector(compare:)] retain]; } -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger section = [indexPath section]; NSUInteger row = [indexPath row]; NSString *key = [keys objectAtIndex:section]; NSArray *nameSection = [names objectForKey:key]; static NSString *SectionsTableIdentifier = @"SectionsTableIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SectionsTableIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SectionsTableIdentifier] autorelease]; } cell.textLabel.text = [nameSection objectAtIndex:row]; return cell; } The exception happens on the method "cellForRowAtIndexPath" in the line cell.textLabel.text = [nameSection objectAtIndex:row]; The error message is Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x6832440 Where ever I use "[nameSection objectAtIndex:row];" type of statement it always get exception.

    Read the article

  • delegate issues in Xcode

    - by trludt
    .h file #import <UIKit/UIKit.h> @interface AddEventViewController : UIViewController <UITextViewDelegate> @end .m file @property (weak, nonatomic) IBOutlet UITextField *textField1; @property (weak, nonatomic) IBOutlet UITextField *textField2; @property (weak, nonatomic) IBOutlet UITextField *textField3; - (IBAction)textFieldReturn:(id)sender; @end @implementation AddEventViewController @synthesize textField1, textField2, textField3; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (IBAction)textFieldReturn:(id)sender; { [sender resignFirstResponder]; } - (void)viewDidLoad { [super viewDidLoad]; self.textField1.delegate = self; textField1.delegate = self; // Do any additional setup after loading the view. } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)touchesBegan: (NSSet *) touches withEvent: (UIEvent *)event { if (textField1) { if ([textField1 canResignFirstResponder]) [textField1 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; if (textField2) { if ([textField2 canResignFirstResponder]) [textField2 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; if (textField3) { if ([textField3 canResignFirstResponder]) [textField3 resignFirstResponder]; } [super touchesBegan: touches withEvent: event]; } - (BOOL)textFieldShouldReturn:(UITextField *)textField { [textField1 resignFirstResponder]; return NO; [textField2 resignFirstResponder]; return NO; [textField3 resignFirstResponder]; return NO; } @end Ok so im getting the yellow bug symbol on the lines: - (void)viewDidLoad { [super viewDidLoad]; self.textField1.delegate = self; textField1.delegate = self; } I don't know how to delegate all of my textFields? how do i make this textFieldReturn work for all of my textFields.. that viewDidLoad area has to be the problem, because everything else works good...

    Read the article

  • Lighting get darker when texture is aplied

    - by noah
    Im using OpenGL ES 1.1 for iPhone. I'm attempting to implement a skybox in my 3d world and started out by following one of Jeff Lamarches tutorials on creating textures. Heres the tutorial: iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6_25.html Ive successfully added the image to my 3d world but am not sure why the lighting on the other shapes has changed so much. I want the shapes to be the original color and have the image in the background. Before: https://www.dropbox.com/s/ojmb8793vj514h0/Screen%20Shot%202012-10-01%20at%205.34.44%20PM.png After: https://www.dropbox.com/s/8v6yvur8amgudia/Screen%20Shot%202012-10-01%20at%205.35.31%20PM.png Heres the init OpenGL: - (void)initOpenGLES1 { glShadeModel(GL_SMOOTH); // Enable lighting glEnable(GL_LIGHTING); // Turn the first light on glEnable(GL_LIGHT0); const GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0}; const GLfloat lightDiffuse[] = {0.8, 0.8, 0.8, 1.0}; const GLfloat matAmbient[] = {0.3, 0.3, 0.3, 0.5}; const GLfloat matDiffuse[] = {1.0, 1.0, 1.0, 1.0}; const GLfloat matSpecular[] = {1.0, 1.0, 1.0, 1.0}; const GLfloat lightPosition[] = {0.0, 0.0, 1.0, 0.0}; const GLfloat lightShininess = 100.0; //Configure OpenGL lighting glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lightShininess); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); // Define a cutoff angle glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 40.0); // Set the clear color glClearColor(0, 0, 0, 1.0f); // Projection Matrix config glMatrixMode(GL_PROJECTION); glLoadIdentity(); CGSize layerSize = self.view.layer.frame.size; // Swapped height and width for landscape mode gluPerspective(45.0f, (GLfloat)layerSize.height / (GLfloat)layerSize.width, 0.1f, 750.0f); [self initSkyBox]; // Modelview Matrix config glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // This next line is not really needed as it is the default for OpenGL ES glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // Enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); } Heres the drawSkybox that gets called in the drawFrame method: -(void)drawSkyBox { glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); static const SSVertex3D vertices[] = { {-1.0, 1.0, -0.0}, { 1.0, 1.0, -0.0}, {-1.0, -1.0, -0.0}, { 1.0, -1.0, -0.0} }; static const SSVertex3D normals[] = { {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0} }; static const GLfloat texCoords[] = { 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 0.5, 0.0 }; glLoadIdentity(); glTranslatef(0.0, 0.0, -3.0); glBindTexture(GL_TEXTURE_2D, texture[0]); glVertexPointer(3, GL_FLOAT, 0, vertices); glNormalPointer(GL_FLOAT, 0, normals); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); } Heres the init Skybox: -(void)initSkyBox { // Turn necessary features on glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_SRC_COLOR); // Bind the number of textures we need, in this case one. glGenTextures(1, &texture[0]); // create a texture obj, give unique ID glBindTexture(GL_TEXTURE_2D, texture[0]); // load our new texture name into the current texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); NSString *path = [[NSBundle mainBundle] pathForResource:@"space" ofType:@"jpg"]; NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; UIImage *image = [[UIImage alloc] initWithData:texData]; GLuint width = CGImageGetWidth(image.CGImage); GLuint height = CGImageGetHeight(image.CGImage); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); void *imageData = malloc( height * width * 4 ); // times 4 because will write one byte for rgb and alpha CGContextRef cgContext = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big ); // Flip the Y-axis CGContextTranslateCTM (cgContext, 0, height); CGContextScaleCTM (cgContext, 1.0, -1.0); CGColorSpaceRelease( colorSpace ); CGContextClearRect( cgContext, CGRectMake( 0, 0, width, height ) ); CGContextDrawImage( cgContext, CGRectMake( 0, 0, width, height ), image.CGImage ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); CGContextRelease(cgContext); free(imageData); [image release]; [texData release]; } Any help is greatly appreciated.

    Read the article

  • Texture and Lighting Issue in 3D world

    - by noah
    Im using OpenGL ES 1.1 for iPhone. I'm attempting to implement a skybox in my 3d world and started out by following one of Jeff Lamarches tutorials on creating textures. Heres the tutorial: iphonedevelopment.blogspot.com/2009/05/opengl-es-from-ground-up-part-6_25.html Ive successfully added the image to my 3d world but am not sure why the lighting on the other shapes has changed so much. I want the shapes to be the original color and have the image in the background. Before: https://www.dropbox.com/s/ojmb8793vj514h0/Screen%20Shot%202012-10-01%20at%205.34.44%20PM.png After: https://www.dropbox.com/s/8v6yvur8amgudia/Screen%20Shot%202012-10-01%20at%205.35.31%20PM.png Heres the init OpenGL: - (void)initOpenGLES1 { glShadeModel(GL_SMOOTH); // Enable lighting glEnable(GL_LIGHTING); // Turn the first light on glEnable(GL_LIGHT0); const GLfloat lightAmbient[] = {0.2, 0.2, 0.2, 1.0}; const GLfloat lightDiffuse[] = {0.8, 0.8, 0.8, 1.0}; const GLfloat matAmbient[] = {0.3, 0.3, 0.3, 0.5}; const GLfloat matDiffuse[] = {1.0, 1.0, 1.0, 1.0}; const GLfloat matSpecular[] = {1.0, 1.0, 1.0, 1.0}; const GLfloat lightPosition[] = {0.0, 0.0, 1.0, 0.0}; const GLfloat lightShininess = 100.0; //Configure OpenGL lighting glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, matAmbient); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, matDiffuse); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, matSpecular); glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, lightShininess); glLightfv(GL_LIGHT0, GL_AMBIENT, lightAmbient); glLightfv(GL_LIGHT0, GL_DIFFUSE, lightDiffuse); glLightfv(GL_LIGHT0, GL_POSITION, lightPosition); // Define a cutoff angle glLightf(GL_LIGHT0, GL_SPOT_CUTOFF, 40.0); // Set the clear color glClearColor(0, 0, 0, 1.0f); // Projection Matrix config glMatrixMode(GL_PROJECTION); glLoadIdentity(); CGSize layerSize = self.view.layer.frame.size; // Swapped height and width for landscape mode gluPerspective(45.0f, (GLfloat)layerSize.height / (GLfloat)layerSize.width, 0.1f, 750.0f); [self initSkyBox]; // Modelview Matrix config glMatrixMode(GL_MODELVIEW); glLoadIdentity(); // This next line is not really needed as it is the default for OpenGL ES glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glDisable(GL_BLEND); // Enable depth testing glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); glDepthMask(GL_TRUE); } Heres the drawSkybox that gets called in the drawFrame method: -(void)drawSkyBox { glDisable(GL_LIGHTING); glDisable(GL_DEPTH_TEST); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); static const SSVertex3D vertices[] = { {-1.0, 1.0, -0.0}, { 1.0, 1.0, -0.0}, {-1.0, -1.0, -0.0}, { 1.0, -1.0, -0.0} }; static const SSVertex3D normals[] = { {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0}, {0.0, 0.0, 1.0} }; static const GLfloat texCoords[] = { 0.0, 0.5, 0.5, 0.5, 0.0, 0.0, 0.5, 0.0 }; glLoadIdentity(); glTranslatef(0.0, 0.0, -3.0); glBindTexture(GL_TEXTURE_2D, texture[0]); glVertexPointer(3, GL_FLOAT, 0, vertices); glNormalPointer(GL_FLOAT, 0, normals); glTexCoordPointer(2, GL_FLOAT, 0, texCoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glEnable(GL_LIGHTING); glEnable(GL_DEPTH_TEST); } Heres the init Skybox: -(void)initSkyBox { // Turn necessary features on glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_ONE, GL_SRC_COLOR); // Bind the number of textures we need, in this case one. glGenTextures(1, &texture[0]); // create a texture obj, give unique ID glBindTexture(GL_TEXTURE_2D, texture[0]); // load our new texture name into the current texture glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); NSString *path = [[NSBundle mainBundle] pathForResource:@"space" ofType:@"jpg"]; NSData *texData = [[NSData alloc] initWithContentsOfFile:path]; UIImage *image = [[UIImage alloc] initWithData:texData]; GLuint width = CGImageGetWidth(image.CGImage); GLuint height = CGImageGetHeight(image.CGImage); CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); void *imageData = malloc( height * width * 4 ); // times 4 because will write one byte for rgb and alpha CGContextRef cgContext = CGBitmapContextCreate( imageData, width, height, 8, 4 * width, colorSpace, kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big ); // Flip the Y-axis CGContextTranslateCTM (cgContext, 0, height); CGContextScaleCTM (cgContext, 1.0, -1.0); CGColorSpaceRelease( colorSpace ); CGContextClearRect( cgContext, CGRectMake( 0, 0, width, height ) ); CGContextDrawImage( cgContext, CGRectMake( 0, 0, width, height ), image.CGImage ); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, imageData); CGContextRelease(cgContext); free(imageData); [image release]; [texData release]; } Any help is greatly appreciated.

    Read the article

  • Core Data migration failing with error: Failed to save new store after first pass of migration

    - by unforgiven
    In the past I had already implemented successfully automatic migration from version 1 of my data model to version 2. Now, using SDK 3.1.3, migrating from version 2 to version 3 fails with the following error: Unresolved error Error Domain=NSCocoaErrorDomain Code=134110 UserInfo=0x5363360 "Operation could not be completed. (Cocoa error 134110.)", { NSUnderlyingError = Error Domain=NSCocoaErrorDomain Code=256 UserInfo=0x53622b0 "Operation could not be completed. (Cocoa error 256.)"; reason = "Failed to save new store after first pass of migration."; } I have tried automatic migration using NSMigratePersistentStoresAutomaticallyOption and NSInferMappingModelAutomaticallyOption and also migration using only NSMigratePersistentStoresAutomaticallyOption, providing a mapping model from v2 to v3. I see the above error logged, and no object is available in the application. However, if I quit the application and reopen it, everything is in place and working. The Core Data methods I am using are the following ones - (NSManagedObjectModel *)managedObjectModel { if (managedObjectModel != nil) { return managedObjectModel; } NSString *path = [[NSBundle mainBundle] pathForResource:@"MYAPP" ofType:@"momd"]; NSURL *momURL = [NSURL fileURLWithPath:path]; managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:momURL]; return managedObjectModel; } - (NSManagedObjectContext *) managedObjectContext { if (managedObjectContext != nil) { return managedObjectContext; } NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; if (coordinator != nil) { managedObjectContext = [[NSManagedObjectContext alloc] init]; [managedObjectContext setPersistentStoreCoordinator: coordinator]; } return managedObjectContext; } - (NSPersistentStoreCoordinator *)persistentStoreCoordinator { if (persistentStoreCoordinator != nil) { return persistentStoreCoordinator; } NSURL *storeUrl = [NSURL fileURLWithPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP.sqlite"]]; NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, nil]; NSError *error = nil; persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: [self managedObjectModel]]; if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeUrl options:options error:&error]) { // Handle error NSLog(@"Unresolved error %@, %@", error, [error userInfo]); } return persistentStoreCoordinator; } In the simulator, I see that this generates a MYAPP~.sqlite files and a MYAPP.sqlite file. I tried to remove the MYAPP~.sqlite file, but BOOL oldExists = [[NSFileManager defaultManager] fileExistsAtPath: [[self applicationDocumentsDirectory] stringByAppendingPathComponent: @"MYAPP~.sqlite"]]; always returns NO. Any clue? Am I doing something wrong? Thank you in advance.

    Read the article

  • EXC_BAD_ACCESS error on a UITableView with ARC?

    - by Arnaud Drizard
    I am building a simple app with a custom bar tab which loads the content of the ViewController from a UITableView located in another ViewController. However, every time I try to scroll on the tableview, I get an exc_bad_access error. I enabled NSzombies and guard malloc to get more info on the issue. In the console I get: "message sent to deallocated instance 0x19182f20" and after profiling I get: # Address Category Event Type RefCt Timestamp Size Responsible Library Responsible Caller 56 0x19182f20 FirstTabBarViewController Zombie -1 00:16.613.309 0 UIKit -[UIScrollView(UIScrollViewInternal) _scrollViewWillBeginDragging] Here is a bit of the code of the ViewController in which the error occurs: .h file: #import <UIKit/UIKit.h> #import "DataController.h" @interface FirstTabBarViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> { IBOutlet UITableView* tabBarTable; } @property (strong, nonatomic) IBOutlet UIView *mainView; @property (strong, nonatomic) IBOutlet UITableView *tabBarTable; @property (nonatomic, strong) DataController *messageDataController; @end .m file: #import "FirstTabBarViewController.h" #import "DataController.h" @interface FirstTabBarViewController () @end @implementation FirstTabBarViewController @synthesize tabBarTable=_tabBarTable; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { // Custom initialization } return self; } - (void)viewDidLoad { [super viewDidLoad]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)awakeFromNib { [super awakeFromNib]; self.messageDataController=[[DataController alloc] init]; } - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [self.messageDataController countOfList]; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"mainCell"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil){ cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; }; NSString *expenseAtIndex = [self.messageDataController objectInListAtIndex:indexPath.row]; [[cell textLabel] setText:expenseAtIndex]; return cell; } - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return NO if you do not want the specified item to be editable. return NO; } @end This FirstTabBarViewController is loaded in the MainViewController with the following custom segue: #import "customTabBarSegue.h" #import "MainViewController.h" @implementation customTabBarSegue -(void) perform { MainViewController *src= (MainViewController *) [self sourceViewController]; UIViewController *dst=(UIViewController *)[self destinationViewController]; for (UIView *view in src.placeholderView.subviews){ [view removeFromSuperview]; } src.currentViewController =dst; [src.placeholderView addSubview:dst.view]; } @end The Datacontroller class is just a simple NSMutableArray containing strings. I am using ARC so I don't understand where the memory management error comes from. Does anybody have a clue? Any help much appreciated ;) Thanks!!

    Read the article

  • Strange crashes when using MPMoviePlayerController in iPad and iPad simulator with iOS 4.2.

    - by Dave L
    I'm getting crashes when trying to play a movie using MPMoviePlayerController on the iPad and in the iPad simulator using iOS 4.2. I am building using xcode 3.2.5 and the 4.2 SDK. When running on an iPad using iOS 3.2 or in the iPad simulator 3.2, the same code works fine, but on an iPad running 4.2 or in the iPad simulator 4.2, it crashes. The crash is due to an exception for calling an unknown selector down somewhere deep in the cocoa libraries, something tries to call a selector called "setHitRectInsets:" on a UIButton object. Also, the crash happens after control has returned to the main event loop. Anybody have any idea what might be causing this? Here is the code (roughly, some extraneous stuff deleted that doesn't seem to have any effect) that is crashing: NSString *fullMovieFilename = [[NSBundle mainBundle] pathForResource:@"movie" ofType:@"m4v"]; NSURL *movieURL = [NSURL fileURLWithPath:fullMovieFilename]; moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL]; moviePlayer.controlStyle = MPMovieControlStyleNone; // crash happens regardless of the setting here [moviePlayer.view setFrame:self.view.bounds]; [self.view addSubview:moviePlayer.view]; [moviePlayer setFullscreen:YES animated:YES]; // crash happens whether i use fullscreen or not [moviePlayer play]; The same code also works just find if I build using Xcode 3.2.3 and the 4.0 SDK. The crash stack trace looks like this: 2011-03-04 23:08:22.017 MyApp[31610:207] -[UIButton setHitRectInsets:]: unrecognized selector sent to instance 0x990bc60 2011-03-04 23:08:22.020 MyApp[31610:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIButton setHitRectInsets:]: unrecognized selector sent to instance 0x990bc60' *** Call stack at first throw: ( 0 CoreFoundation 0x0151abe9 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x0166f5c2 objc_exception_throw + 47 2 CoreFoundation 0x0151c6fb -[NSObject(NSObject) doesNotRecognizeSelector:] + 187 3 CoreFoundation 0x0148c366 ___forwarding___ + 966 4 CoreFoundation 0x0148bf22 _CF_forwarding_prep_0 + 50 5 MediaPlayer 0x011b5bdb -[MPTransportControls createButtonForPart:] + 380 6 MediaPlayer 0x011b65d5 -[MPTransportControls _updateAdditions:removals:forPart:] + 110 7 MediaPlayer 0x011b4d78 -[MPTransportControls _reloadViewWithAnimation:] + 299 8 MediaPlayer 0x011b621a -[MPTransportControls setVisibleParts:] + 49 9 MediaPlayer 0x011b6e4a -[MPTransportControls initWithFrame:] + 173 10 MediaPlayer 0x011f9188 -[MPInlineTransportControls initWithFrame:] + 78 11 MediaPlayer 0x011f193a -[MPInlineVideoOverlay layoutSubviews] + 158 12 QuartzCore 0x00d6e451 -[CALayer layoutSublayers] + 181 13 QuartzCore 0x00d6e17c CALayerLayoutIfNeeded + 220 14 QuartzCore 0x00d6e088 -[CALayer layoutIfNeeded] + 111 15 MediaPlayer 0x011f130c -[MPInlineVideoOverlay setAllowsWirelessPlayback:] + 46 16 MediaPlayer 0x011f5b0d -[MPInlineVideoViewController _overlayView] + 526 17 MediaPlayer 0x011f6359 -[MPInlineVideoViewController _layoutForItemTypeAvailable] + 1350 18 Foundation 0x000e56c1 _nsnote_callback + 145 19 CoreFoundation 0x014f2f99 __CFXNotificationPost_old + 745 20 CoreFoundation 0x0147233a _CFXNotificationPostNotification + 186 21 Foundation 0x000db266 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134 22 Foundation 0x000e75a9 -[NSNotificationCenter postNotificationName:object:] + 56 23 MediaPlayer 0x01184dd6 -[MPAVItem _updateForNaturalSizeChange] + 278 24 MediaPlayer 0x011818e4 __-[MPAVItem blockForDirectAVControllerNotificationReferencingItem:]_block_invoke_1 + 82 25 MediaPlayer 0x011899ba -[MPAVController _postMPAVControllerSizeDidChangeNotificationWithItem:] + 138 26 Foundation 0x000e56c1 _nsnote_callback + 145 27 CoreFoundation 0x014f2f99 __CFXNotificationPost_old + 745 28 CoreFoundation 0x0147233a _CFXNotificationPostNotification + 186 29 Foundation 0x000db266 -[NSNotificationCenter postNotificationName:object:userInfo:] + 134 30 Celestial 0x052a35b2 -[NSObject(NSObject_AVShared) postNotificationWithDescription:] + 176 31 Celestial 0x052ab214 -[AVController fpItemNotification:sender:] + 735 32 Celestial 0x052b5305 -[AVPlaybackItem fpItemNotificationInfo:] + 640 33 Celestial 0x052a3d5c -[AVObjectRegistry safeInvokeWithDescription:] + 211 34 Foundation 0x000fa9a6 __NSThreadPerformPerform + 251 35 CoreFoundation 0x014fc01f __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 15 36 CoreFoundation 0x0145a28b __CFRunLoopDoSources0 + 571 37 CoreFoundation 0x01459786 __CFRunLoopRun + 470 38 CoreFoundation 0x01459240 CFRunLoopRunSpecific + 208 39 CoreFoundation 0x01459161 CFRunLoopRunInMode + 97 40 GraphicsServices 0x01e4f268 GSEventRunModal + 217 41 GraphicsServices 0x01e4f32d GSEventRun + 115 42 UIKit 0x0038a42e UIApplicationMain + 1160 43 MyApp 0x0000837a main + 102 44 MpApp 0x00002009 start + 53 ) terminate called after throwing an instance of 'NSException' Been fighting with this for several days, and have searched the internet quite a bit for anybody having similar problems, all with no luck. Any suggestions would be greatly appreciated.

    Read the article

  • UIWebView leak? Can someone confirm?

    - by Shaggy Frog
    I was leak-testing my current project and I'm stumped. I've been browsing like crazy and tried everything except chicken sacrifice. I just created a tiny toy project app from scratch and I can duplicate the leak in there. So either UIWebView has a leak or I'm doing something really silly. Essentially, it boils down to a loadRequest: call to a UIWebView object, given an URLRequest built from an NSURL which references a file URL, for a file in the app bundle, which lives inside a folder that Xcode is including by reference. Phew. The leak is intermittent but still happens ~75% of the time (in about 20 tests it happened about 15 times). It only happens on the device -- this does not leak in the simulator. I am testing targeting both iPhone OS 3.1.2 and 3.1.3, on an original (1st Gen) iPod Touch that is using iPhone OS 3.1.3. To reproduce, just create a project from scratch. Add a UIWebView to the RootViewController's .xib, hook it up via IBOutlet. In the Finder, create a folder named "html" inside your project's folder. Inside that folder, create a file named "dummy.html" that has the word "Test" in it. (Does not need to be valid HTML.) Then add the html folder to your project in Xcode by choosing "Create Folder References for any added folders" Add the following to viewDidLoad NSString* resourcePath = [[NSBundle mainBundle] resourcePath]; NSString* filePath = [[resourcePath stringByAppendingPathComponent:@"html"] stringByAppendingPathComponent:@"dummy.html"]; NSURL* url = [[NSURL alloc] initFileURLWithPath:filePath]; NSURLRequest* request = [NSURLRequest requestWithURL:url]; // <-- this creates the leak! [browserView loadRequest:request]; [url release]; I've tried everything from setting delegate for the UIWebView and implementing UIWebViewDelegate, to not setting a delegate in IB, to not setting a delegate in IB and explicitly setting the web view's delegate property to nil, to using alloc/init instead of getting autoreleased NSURLRequests (and/or NSURLs)... I tried the answer to a similar question (setting the shared URL cache to empty) and that did not help. Can anyone help?

    Read the article

  • How can I close a Window using the OS-X ScriptingBridge framework, from Perl?

    - by Gavin Brock
    Problem... Since MacPerl is no longer supported on 64bit perl, I am trying alternative frameworks to control Terminal.app. I am trying the ScriptingBridge, but have run into a problem passing an enumerated string to the closeSaving method using the PerlObjCBridge. I want to call: typedef enum { TerminalSaveOptionsYes = 'yes ' /* Save the file. */, TerminalSaveOptionsNo = 'no ' /* Do not save the file. */, TerminalSaveOptionsAsk = 'ask ' /* Ask the user whether or not to save the file. */ } TerminalSaveOptions; - (void) closeSaving:(TerminalSaveOptions)saving savingIn:(NSURL *)savingIn; // Close a document. Attempted Solution... I have tried: #!/usr/bin/perl use strict; use warnings; use Foundation; # Load the ScriptingBridge framework NSBundle->bundleWithPath_('/System/Library/Frameworks/ScriptingBridge.framework')->load; @SBApplication::ISA = qw(PerlObjCBridge); # Set up scripting bridge for Terminal.app my $terminal = SBApplication->applicationWithBundleIdentifier_("com.apple.terminal"); # Open a new window, get back the tab my $tab = $terminal->doScript_in_('exec sleep 60', undef); warn "Opened tty: ".$tab->tty->UTF8String; # Yes, it is a tab # Now try to close it # Simple idea eval { $tab->closeSaving_savingIn_('no ', undef) }; warn $@ if $@; # Try passing a string ref my $no = 'no '; eval { $tab->closeSaving_savingIn_(\$no, undef) }; warn $@ if $@; # Ok - get a pointer to the string my $pointer = pack("P4", $no); eval { $tab->closeSaving_savingIn_($pointer, undef) }; warn $@ if $@; eval { $tab->closeSaving_savingIn_(\$pointer, undef) }; warn $@ if $@; # Try a pointer decodes as an int, like PerlObjCBridge uses my $int_pointer = unpack("L!", $pointer); eval { $tab->closeSaving_savingIn_($int_pointer, undef) }; warn $@ if $@; eval { $tab->closeSaving_savingIn_(\$int_pointer, undef) }; warn $@ if $@; # Aaarrgghhhh.... As you can see, all my guesses at how to pass the enumerated string fail. Before you flame me... I know that I could use another language (ruby, python, cocoa) to do this but that would require translating the rest of the code. I might be able to use CamelBones, but I don't want to assume my users have it installed. I could also use the NSAppleScript framework (assuming I went to the trouble of finding the Tab and Window IDs) but it seems odd to have to resort to it for just this one call.

    Read the article

  • Objective-c - How to serialize audio file into small packets that can be played?

    - by vfn
    Hi there, So, I would like to get a sound file and convert it in packets, and send it to another computer. I would like that the other computer be able to play the packets as they arrive. I am using AVAudioPlayer to try to play this packets, but I couldn't find a proper way to serialize the data on the peer1 that the peer2 can play. The scenario is, peer1 has a audio file, split the audio file in many small packets, put them on a NSData and send them to peer2. Peer 2 receive the packets and play one by one, as they arrive. Does anyone have know how to do this? or even if it is possible? EDIT: Here it is some piece of code to illustrate what I would like to achieve. // This code is part of the peer1, the one who sends the data - (void)sendData { int packetId = 0; NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"myAudioFile" ofType:@"wav"]; NSData *soundData = [[NSData alloc] initWithContentsOfFile:soundFilePath]; NSMutableArray *arraySoundData = [[NSMutableArray alloc] init]; // Spliting the audio in 2 pieces // This is only an illustration // The idea is to split the data into multiple pieces // dependin on the size of the file to be sent NSRange soundRange; soundRange.length = [soundData length]/2; soundRange.location = 0; [arraySoundData addObject:[soundData subdataWithRange:soundRange]]; soundRange.length = [soundData length]/2; soundRange.location = [soundData length]/2; [arraySoundData addObject:[soundData subdataWithRange:soundRange]]; for (int i=0; i // This is the code on peer2 that would receive an play the piece of audio on each packet - (void) receiveData:(NSData *)data { NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:data]; if ([unarchiver containsValueForKey:PACKET_ID]) NSLog(@"DECODED PACKET_ID: %i", [unarchiver decodeIntForKey:PACKET_ID]); if ([unarchiver containsValueForKey:PACKET_SOUND_DATA]) { NSLog(@"DECODED sound"); NSData *sound = (NSData *)[unarchiver decodeObjectForKey:PACKET_SOUND_DATA]; if (sound == nil) { NSLog(@"sound is nil!"); } else { NSLog(@"sound is not nil!"); AVAudioPlayer *audioPlayer = [AVAudioPlayer alloc]; if ([audioPlayer initWithData:sound error:nil]) { [audioPlayer prepareToPlay]; [audioPlayer play]; } else { [audioPlayer release]; NSLog(@"Player couldn't load data"); } } } [unarchiver release]; } So, here is what I am trying to achieve...so, what I really need to know is how to create the packets, so peer2 can play the audio. It would be a kind of streaming. Yes, for now I am not worried about the order that the packet are received or played...I only need to get the sound sliced and them be able to play each piece, each slice, without need to wait for the whole file be received by peer2. Thanks!

    Read the article

  • extract data from Plist to array and dictionary

    - by Boaz
    Hi I made a plist that looks like that: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList 1.0.dtd"> <plist version="1.0"> <array> <array> <dict> <key>Company</key> <string>xxx</string> <key>Title</key> <string>VP Marketing</string> <key>Name</key> <string>Alon ddfr</string> </dict> <dict> <key>Name</key> <string>Adam Ben Shushan</string> <key>Title</key> <string>CEO</string> <key>Company</key> <string>Shushan ltd.</string> </dict> </array> <array> <dict> <key>Company</key> <string>xxx</string> <key>Title</key> <string>CTO</string> <key>Name</key> <string>Boaz frf</string> </dict> </array> </array> </plist> Now I want to extract the data like that (all the 'A' for key "Name" to one section and all the 'B' "Name" to other one): NSString *plistpath = [[NSBundle mainBundle] pathForResource:@"PeopleData" ofType:@"plist"]; NSMutableArray *attendees = [[NSMutableArray alloc] initWithContentsOfFile:plistpath]; listOfPeople = [[NSMutableArray alloc] init];//Add items NSDictionary *indexADict = [NSDictionary dictionaryWithObject:[[attendees objectAtIndex:0] objectForKey:@"Name"] forKey:@"Profiles"]; NSDictionary *indexBDict = [NSDictionary dictionaryWithObject:[[attendees objectAtIndex:1] objectForKey:@"Name"] forKey:@"Profiles"]; [listOfPeople addObject:indexADict]; [listOfPeople addObject:indexBDict]; This in order to view them in sectioned tableView. I know that the problem is here: NSDictionary *indexADict = [NSDictionary dictionaryWithObject:[[attendees objectAtIndex:0] objectForKey:@"Name"] forKey:@"Profiles"]; But I just can't figure how to do it right. Thanks.

    Read the article

  • Odd values/movement with UITouch and CGPoint.

    - by Joshua
    I'm getting odd numbers from UITouch and CGPoint and one is different, I also think this maybe causing a flickering affect in my app when I try to move something by following a touch. This is the code I'm using: - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { NSLog(@"touchDown"); UITouch *touch = [touches anyObject]; firstTouch = [touch locationInView:self.view]; if (CGRectContainsPoint(but.frame, firstTouch)) { butContains = YES; NSLog(@"butContains = %d", butContains); } } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; currentTouch = [touch locationInView:self.view]; NSInteger x = currentTouch.x; NSInteger y = currentTouch.y; CGFloat CGX = (CGFloat)x; CGFloat CGY = (CGFloat)y; if (butContains == YES) { NSLog(@"touch in subView/contentView"); sub.frame = CGRectMake(CGX, CGY, 130.0, 21.0); } NSLog(@"touch moved"); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; currentTouch = [touch locationInView:self.view]; NSLog(@"User tapped at %@", NSStringFromCGPoint(currentTouch)); NSLog(@"Point %a, %a", currentTouch.x, currentTouch.y); NSInteger x = currentTouch.x; NSInteger y = currentTouch.y; NSLog(@"Point %a, %a", y, x); CGFloat CGX = (CGFloat)x; CGFloat CGY = (CGFloat)y; NSLog(@"Point %g, %g", CGX, CGY); if (butContains == YES) { NSLog(@"touch in subView/contentView"); sub.frame = CGRectMake(CGX, CGY, 130.0, 21.0); } butContains = NO; NSLog(@"touch ended"); } - (IBAction)add:(id)sender{ InSightViewController *contentView = [[InSightViewController alloc] initWithNibName:@"SubView" bundle:[NSBundle mainBundle]]; [contentView loadView]; [self.view insertSubview:contentView.view atIndex:0]; } This is what I get from the touchesEnded method in the Debugger. 2010-04-20 20:06:13.045 InSight[25042:207] User tapped at {50, 78} 2010-04-20 20:06:13.047 InSight[25042:207] Point 0x1.9p+5, 0x1.38p+6 2010-04-20 20:06:13.048 InSight[25042:207] Point 0x1.900000027p-1037, 0x1.38p+6 2010-04-20 20:06:13.048 InSight[25042:207] Point 50, 78 And this is what's happening in the Simulator. fwdr.org/file:y8bd As this is a complicated problem this is the source code of my XCode Project aswell. http://cl.ly/Qjj

    Read the article

< Previous Page | 11 12 13 14 15 16 17 18 19  | Next Page >