cocoa-touch

UIColor colorWithRed:green:blue:alpha: always returns white unless one argument is 0

别等时光非礼了梦想. 提交于 2019-12-28 23:05:33
问题 I am using [UIColor colorWithRed:136 green:155 blue:218 alpha:1.0]; to change the background color of my table view cells. But for some reason the background just stays white. If I try [UIColor colorWithRed:0 green:155 blue:218 alpha:1.0]; the color changes. This does not make sense to me. Any advice or tips? 回答1: The parameter aren't a values of 0 to 255 but a float between 0.0 and 1.0: [UIColor colorWithRed:0.0f/255.0f green:155.0f/255.0f blue:218.0f/255.0f alpha:1.0f]; 回答2: The values need

Data repeat in UITableView when scrolling

跟風遠走 提交于 2019-12-28 19:21:10
问题 I use bellow codes to show data on TableView but when scrolling, data repeat and other data lost. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return [FileCompletedArray count]; } cellForRowatindexpath (): - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CellIdentifier";

How do I launch my settings bundle from my application?

断了今生、忘了曾经 提交于 2019-12-28 13:58:49
问题 I am working on adding in a settings bundle for my application as a cheap way of getting a GUI on my preferences. Is it possible to launch this from a button in my application or will my users always have to access it manually via the built in settings application? 回答1: They may have to go to the settings application, depending on how you do it. See this document, the Applications Preferences section. Here's the relevant section from the introduction: Adding your application preferences to

C function calling objective C functions

大兔子大兔子 提交于 2019-12-28 13:57:21
问题 I've a c function in my viewController.m. int abc(int a, char* b) { //do something } I also have a function -(void) callIncomingClass { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //set the position of the button button.frame = CGRectMake(100, 170, 100, 30); //set the button's title [button setTitle:@"Click Me!" forState:UIControlStateNormal]; //add the button to the view [self.view addSubview:button]; } Now I want to call callIncomingClass from within the function

C function calling objective C functions

狂风中的少年 提交于 2019-12-28 13:57:11
问题 I've a c function in my viewController.m. int abc(int a, char* b) { //do something } I also have a function -(void) callIncomingClass { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //set the position of the button button.frame = CGRectMake(100, 170, 100, 30); //set the button's title [button setTitle:@"Click Me!" forState:UIControlStateNormal]; //add the button to the view [self.view addSubview:button]; } Now I want to call callIncomingClass from within the function

String length with given font to fit UITextView 2 - The Return

时光总嘲笑我的痴心妄想 提交于 2019-12-28 13:57:11
问题 In this question I asked for a good way to truncate a string to fit a given UITextView. Since there was no way provided by the SDK directly, I've ended up writing the recursive method below (only called by the following public method). However, this doesn't work unless I subtract a fudge factor of 15 (kFudgeFactor) from the field width when calculating the string's height. If I don't do that, the string returned is actually too long for the field, and displays in an extra line below it.

iPhone - debugging “pointer being freed was not allocated” errors

风格不统一 提交于 2019-12-28 13:54:28
问题 When over freeing a pointer you may see an error such as "pointer being freed was not allocated" When debugging with the simulator, I add a build argument MallocStackLogging = YES - this allows me to use malloc_history in the terminal to track down where I have over freed a pointer. If I debug on the device with this build argument I get all sorts of console errors "cannot create stack log files" etc. Oddly, I get some over freed pointer errors appearing on the device, but not on the

How can I create my own methods which take a block as an argument and which I can call later?

眉间皱痕 提交于 2019-12-28 13:51:44
问题 How can I create my own methods which take a block as an argument and which I can call later? I have tried following things. #import <UIKit/UIKit.h> typedef void (^viewCreator)(void); @interface blocks2ViewController : UIViewController { } -(void)createButtonUsingBlocks:(viewCreator *)block; @end - (void)viewDidLoad { [super viewDidLoad]; [self createButtonUsingBlocks:^(NSString * name) { UIButton *dummyButton = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 200, 100)]; dummyButton

How can I create my own methods which take a block as an argument and which I can call later?

不想你离开。 提交于 2019-12-28 13:51:16
问题 How can I create my own methods which take a block as an argument and which I can call later? I have tried following things. #import <UIKit/UIKit.h> typedef void (^viewCreator)(void); @interface blocks2ViewController : UIViewController { } -(void)createButtonUsingBlocks:(viewCreator *)block; @end - (void)viewDidLoad { [super viewDidLoad]; [self createButtonUsingBlocks:^(NSString * name) { UIButton *dummyButton = [[UIButton alloc]initWithFrame:CGRectMake(50, 50, 200, 100)]; dummyButton

UITableView Not Respecting heightForHeaderInSection/heightForFooterInSection?

冷暖自知 提交于 2019-12-28 12:15:50
问题 I have a UITableView where in some instances, certain sections have zero rows. My goal is that when this is true, I don't want any wasted space in the table view, it should look like there's no data. The problem I'm having is with the header and footer for the sections, which are showing even if there's no row and despite me overriding the delegate method to return 0.0f. Here's what it looks like - you can see the ~20p of gray space at the top there, headers and footers of about 10p each for