其實這應該也沒啥,不過對我這腦容量不足的人應該還是很有用,最主要就是兩點。
1.設定UIScrollView的大小
2.scroll到指定位置
首先設定大小的部份
//init出來並且設定位置
UIScrollView *myScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
//設定內容大小
[myScrollView setContentSize:CGSizeMake(900, 900)];
//設定可以捲動
[myScrollView setScrollEnabled:YES];
//加進去self
[self.view addSubview:myScrollView];
接著就在需要捲動的地方加上
//point就是要滑動到的點,0,0為原點
[myScrollView setContentOffset:CGPointMake(0, 0) animated:YES];
相關連結
iOS Developer Library
iOS Developer Library - UIScrollView
iOS UIScrollView Scroll to somewhere捲動到指定點
Android adapter getView
因為這getView被問上不少次,其實這東西就像是iOS UITableViewDelegate內的"cellForRowAtIndexPath",只是在android上不僅可以使用於listView也可以使用在gridView,簡單一句話就是"他很好用"。
不過小弟我根本不會寫程式,如果有寫錯的部份就別給我面子捅下去就對了(簡單一個字就是懶...)
以下為自訂row在getView
public View getView(int position, View convertView, ViewGroup parent) {
LayoutInflater inflater=getLayoutInflater();
View row;
//直接去抓xml的方式來定義內容
row=inflater.inflate(R.layout.custom_row, parent, false);
TextView title=(TextView)row.findViewById(R.id.title);
TextView subtitle=(TextView)row.findViewById(R.id.subtitle);
ImageView myImage = (ImageView)row.findViewById(R.id.myImage);
return (row);
}
以下為row的xml內容,基本上就是看你高興...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="left"
>
<ImageView
android:id="@+id/myImage"
android:src="@drawable/my"
android:layout_width="100px"
android:layout_height="100px"
</ImageView>
<LinearLayout
android:gravity="left"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="100px">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="8pt"
android:singleLine="true">
</TextView>
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Subtitle"
android:textSize="6pt"
android:singleLine="true">
</TextView>
</LinearLayout>
</LinearLayout>
基本上到了這邊應該還會有個疑問是那每一個row要怎樣來把資料丟進去?我個人都是建一個class丟進array內來做管理,對我這種腦內記憶力不足的人來說還蠻好用的。
public class MyObj{
private String title;
private String subtitle;
private Drawable imageDrawable;
}
對應到row裡面可以使用下面這方法,其中的"myArray"也請記得先宣告出來
MyObj myObj = (MyObj)myArray.get(position);
相關連結
Android Developer
Android Developer - adapter
Android Developer - listview
iOS URL encode UTF8
URL轉UTF8並使用Apple URL Scheme,“Mail”、“Phone”、“Text”、“Map”、“YouTube”、“iTunes”
Mail
NSString *mail = [NSString stringWithFormat:@"Mail here"];
NSString* urlString = [NSString stringWithFormat:@"mailto:%@", mail];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
Phone
NSString *tel = [NSString stringWithFormat:@"Phone number here"];
NSString* urlString = [NSString stringWithFormat:@"tel:%@", tel];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
可參考"iOS dial a phone call 在app內撥電話"
Text
NSString *tel = [NSString stringWithFormat:@"Phone number here"];
NSString* urlString = [NSString stringWithFormat:@"sms:%@", tel];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
MAP
NSString *address = [NSString stringWithFormat:@"address here"];
NSString* urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?q=%@", address];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
※地址部份可用經緯度代替 EX.25.xxxxx,121.xxxxxx(中間使用逗號隔開)
Map - Native
NSString *addressA = [NSString stringWithFormat:@"addressA here"];
NSString *addressB = [NSString stringWithFormat:@"addressB here"];
NSString* urlString = [NSString stringWithFormat:@"hhttp://maps.google.com/maps?daddr=%@&saddr=%@", addressA, addressB];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
※地址部份可用經緯度代替 EX.25.xxxxx,121.xxxxxx(中間使用逗號隔開)
Youtube
NSString *id = [NSString stringWithFormat:@"Youtube id here"];
NSString* urlString = [NSString stringWithFormat:@"http://www.youtube.com/v/%@", id];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
iTunes
NSString *id = [NSString stringWithFormat:@"iTunes id here"];
NSString* urlString = [NSString stringWithFormat:@"hhttp://itunes.apple.com/tw/app/halftone/id%@", id];
NSString *escaped = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:escaped]];
※不同國家store也會有所,此為台灣store
相關連結
iOS Developer Library
iOS Developer Library - Apple URL Scheme Reference
"iOS dial a phone call 在app內撥電話"
iOS NSXMLParser
XML parser在iOS裡面有不少選擇,甚至不少第三方的parser都比官方強勁,不過這篇重點是介紹官方的NSXMLParser。
step1. 先在.h檔加入NSXMLParserDelegate
#import
@interface DemoXML : UIViewController
//xml
NSXMLParser *parser;
NSString *parserCurrent;
}
//xml
@property (nonatomic,retain) NSString *parserCurrent;
@end
step2. .m檔的部份加入property部份
//xml
@synthesize parserCurrent;
step3. .m檔內需要進行parser的部份加入
//需要parser的URL
NSString *parserString = @"需要parser的URL";
//若有特別需要轉碼
NSString *escaped = [parserString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
//NSXMLParser init
parser = [[NSXMLParser alloc] initWithContentsOfURL:[NSURL URLWithString:escaped]];
//設定Delegate
[parser setDelegate:self];
//開始parser
[parser parse];
step4.設定Delegate的部份
//parser < XXXX>
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
//NSLog(@"elementName = %@", elementName);
//NSLog(@"elementName = %d", elementName.length);
//elementName就是其中XXX的部份
parserCurrent = elementName;
}
//parser
-(void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
//NSLog(@"didEndElement => elementName = %@ || namespaceURI = %@ || qName = %@", elementName, namespaceURI, qName);
}
//parser <>XXXXXX>
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
NSLog(@"foundCharacters = %@",string);
//如果XML的Tag名稱與所需相同,就做以下動作
if([parserCurrent isEqual:@"title"]){
//Todo something
}
}
//parser結束
-(void) parserDidEndDocument:(NSXMLParser *)parser{
//todo something
}
相關連結
iOS Developer Library
iOS Developer Library - NSXMLParser
iOS Developer Library - NSXMLParserDelegate Protocol Reference
PHP "Cannot modify header information - headers already sent by"
今天遇上這問題目前是順利解決來紀錄一下,稍微查了一下這可能是UTF8 dom的問題,也可能是buffer這部份的問題,總之我是用以下方是解決。
到"C:\Windows"找出php.ini將"output_buffering"修改為On
※O要大寫
; Output buffering allows you to send header lines (including cookies) even
; after you send body content, at the price of slowing PHP's output layer a
; bit. You can enable output buffering during runtime by calling the output
; buffering functions. You can also enable output buffering for all files by
; setting this directive to On. If you wish to limit the size of the buffer
; to a certain size - you can use a maximum number of bytes instead of 'On', as
; a value for this directive (e.g., output_buffering=4096).
output_buffering = On
修改完後別忘了將apache重新啟動