- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
CGRect contentFrame = CGRectMake(42, 7, 245, 30);
UILabel *contentLabel = [[UILabel alloc] initWithFrame:contentFrame];
I saw the above code in many places and I’m wondering, what’s the source of that chunk of code? Can xcode auto create it when i do something with the GUI?
If not, what about CGRectMake(42, 7, 245, 30) how can i set those numbers without counting pixels?
Thanks
Let me explain you,
A
UITableViewCellis just a view/object representing each row/cell in a tableView. Apple has some predefined styles ofUITableViewCellwith lables, imageView and other objects.You may add any objects on this cell like other views, creating objects w.r.t frame & add on cell’s content View.
You may be seeing the same code everywhere is just it is the simplest way to create a custom cell of your own
UITableViewCell. Either apple may be using this as a default when created a new project with a tableView template. Or it may be copied down from the same reference to explain in their own styles in their own tutorials.This may be just a coincidence.