本文整理汇总了C#中UITableView.ScrollToRow方法的典型用法代码示例。如果您正苦于以下问题:C# UITableView.ScrollToRow方法的具体用法?C# UITableView.ScrollToRow怎么用?C# UITableView.ScrollToRow使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UITableView
的用法示例。
在下文中一共展示了UITableView.ScrollToRow方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnChange
private void OnChange(UITableView table, NSIndexPath ip)
{
var cell = table.CellAt (ip) as Cell;
var size = cell.TextView.Bounds.Size;
var newSize = cell.TextView.SizeThatFits (new CGSize (size.Width, nfloat.MaxValue));
if (size.Height != newSize.Height) {
UIView.AnimationsEnabled = false;
table.BeginUpdates ();
table.EndUpdates ();
UIView.AnimationsEnabled = true;
table.ScrollToRow (ip, UITableViewScrollPosition.Top, false);
}
Items [ip.Row] = cell.TextView.Text;
}
示例2: GetCell
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
var cell = tableView.CellAt (indexPath) as Cell ?? Cell.Create ();
cell.TextView.Text = Items [indexPath.Row];
cell.TextView.Changed += (sender, e) => {
OnChange (tableView, indexPath);
};
cell.TextView.Started += (sender, e) => {
tableView.ScrollToRow (indexPath, UITableViewScrollPosition.Top, true);
};
cell.NeedsUpdateConstraints ();
cell.UpdateConstraintsIfNeeded ();
return cell;
}
示例3: GetCell
public override UITableViewCell GetCell (UITableView tv)
{
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, cellkey);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
cell.TextLabel.Text = Caption;
var offset = (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone) ? 20 : 90;
cell.Frame = new CGRect(cell.Frame.X, cell.Frame.Y, tv.Frame.Width-offset, cell.Frame.Height);
CGSize size = ComputeEntryPosition (tv, cell);
var yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
var width = cell.ContentView.Bounds.Width - size.Width;
if (textalignment == UITextAlignment.Right) {
// Add padding if right aligned
width -= 10;
}
var entryFrame = new CGRect (size.Width, yOffset + 2f, width, size.Height);
if (entry == null) {
entry = CreateTextField (entryFrame);
entry.ValueChanged += (sender, e) => Value = entry.Text;
entry.EditingChanged += (sender, e) => Value = entry.Text;
entry.Ended += (sender, e) => Value = entry.Text;
entry.AllEditingEvents += (sender, e) => Value = entry.Text;
entry.ShouldReturn += delegate {
if (ShouldReturn != null)
return ShouldReturn ();
RootElement root = GetRootElement();
EntryElement focus = null;
if (root == null)
return true;
foreach (var s in root) {
foreach (var e in s) {
if (e == this) {
focus = this;
} else if (focus != null && e is EntryElement) {
focus = e as EntryElement;
break;
}
}
if (focus != null && focus != this)
break;
}
if (focus != this)
focus.BecomeFirstResponder (true);
else
focus.ResignFirstResponder (true);
return true;
};
entry.Started += delegate {
EntryElement self = null;
if (!returnKeyType.HasValue) {
var returnType = UIReturnKeyType.Default;
foreach (var e in Section) {
if (e == this)
self = this;
else if (self != null && e is EntryElement)
returnType = UIReturnKeyType.Next;
}
entry.ReturnKeyType = returnType;
} else
entry.ReturnKeyType = returnKeyType.Value;
tv.ScrollToRow (IndexPath, UITableViewScrollPosition.Middle, true);
};
cell.ContentView.AddSubview (entry);
} else
entry.Frame = entryFrame;
if (becomeResponder){
entry.BecomeFirstResponder ();
becomeResponder = false;
}
entry.KeyboardType = KeyboardType;
entry.AutocapitalizationType = AutocapitalizationType;
entry.AutocorrectionType = AutocorrectionType;
cell.TextLabel.Text = Caption;
cell.TextLabel.Font = TitleFont;
cell.TextLabel.TextColor = TitleColor;
return cell;
}
示例4: SetSelectedRow
public void SetSelectedRow( UITableView tableView, int row )
{
if ( row != SelectedIndex )
{
tableView.BeginUpdates( );
// setup a list with the rows that need to be redrawn
List<NSIndexPath> rowIndices = new List<NSIndexPath>();
// if there was previously a row selected, add it to our list
// so it'll be deselected
if ( SelectedIndex > -1 )
{
rowIndices.Add( NSIndexPath.FromRowSection( SelectedIndex, 0 ) );
}
// setup the newly selected index
SelectedIndex = row;
NSIndexPath activeIndex = NSIndexPath.FromRowSection( SelectedIndex, 0 );
rowIndices.Add( activeIndex );
// force a redraw on the row(s) so their selection state is updated
tableView.ReloadRows( rowIndices.ToArray( ), UITableViewRowAnimation.Fade );
tableView.EndUpdates( );
// make sure the newly selected row comes fully into view
tableView.ScrollToRow( activeIndex, UITableViewScrollPosition.Top, true );
}
}
示例5: GetCell
public override UITableViewCell GetCell (UITableView tv)
{
var cell = tv.DequeueReusableCell (CellKey);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, CellKey);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
} else
RemoveTag (cell, 1);
if (entry == null) {
SizeF size = ComputeEntryPosition (tv, cell);
float yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
float width = cell.ContentView.Bounds.Width - size.Width;
entry = CreateTextField (new RectangleF (size.Width + 30, yOffset, width - 40, size.Height + (height - 44)));
entry.Font = inputFont;
entry.Changed += delegate {
FetchValue ();
};
entry.Ended += delegate {
FetchValue ();
};
/*entry.ShouldReturn += delegate {
if (ShouldReturn != null)
return ShouldReturn ();
RootElement root = GetImmediateRootElement ();
EntryElement focus = null;
if (root == null)
return true;
foreach (var s in root.Sections) {
foreach (var e in s.Elements) {
if (e == this) {
focus = this;
} else if (focus != null && e is EntryElement) {
focus = e as EntryElement;
break;
}
}
if (focus != null && focus != this)
break;
}
if (focus != this)
focus.BecomeFirstResponder (true);
else
focus.ResignFirstResponder (true);
return true;
};*/
entry.Started += delegate {
entry.ReturnKeyType = UIReturnKeyType.Default;
tv.ScrollToRow (IndexPath, UITableViewScrollPosition.Middle, true);
};
}
if (becomeResponder) {
entry.BecomeFirstResponder ();
becomeResponder = false;
}
entry.KeyboardType = KeyboardType;
entry.AutocapitalizationType = AutocapitalizationType;
entry.AutocorrectionType = AutocorrectionType;
cell.TextLabel.Text = Caption;
cell.TextLabel.Font = UIFont.BoldSystemFontOfSize(17);
if (this.IsMandatory)
cell.TextLabel.Text += "*";
cell.ContentView.AddSubview (entry);
return cell;
}
示例6: GetCell
public override UITableViewCell GetCell(UITableView tv)
{
var cell = tv.DequeueReusableCell (CellKey);
if (cell == null) {
cell = new UITableViewCell (UITableViewCellStyle.Default, CellKey);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
} else
RemoveTag (cell, 1);
if (entry == null) {
SizeF size = ComputeEntryPosition (tv, cell);
float yOffset = (cell.ContentView.Bounds.Height - size.Height) / 4 - 1;
float width = cell.ContentView.Bounds.Width - size.Width;
entry = CreateTextField (new RectangleF (size.Width, yOffset, width, size.Height + (height - 11)));
entry.Font = inputFont;
entry.Changed += delegate {
FetchValue ();
};
entry.Ended += delegate {
FetchValue ();
};
entry.Started += delegate {
entry.ReturnKeyType = UIReturnKeyType.Default;
tv.ScrollToRow (IndexPath, UITableViewScrollPosition.Middle, true);
};
}
if (becomeResponder) {
entry.BecomeFirstResponder ();
becomeResponder = false;
}
entry.KeyboardType = KeyboardType;
entry.AutocapitalizationType = AutocapitalizationType;
entry.AutocorrectionType = AutocorrectionType;
cell.TextLabel.Text = Caption;
cell.ContentView.AddSubview (entry);
return cell;
}
示例7: TogglePicker
/// <summary>
/// Shows or hides the nullable picker
/// </summary>
/// <param name="dvc"></param>
/// <param name="tableView"></param>
/// <param name="path"></param>
/// <returns></returns>
private void TogglePicker(DialogViewController dvc, UITableView tableView, NSIndexPath path)
{
var sectionAndIndex = GetMySectionAndIndex(dvc);
if (sectionAndIndex.Key != null)
{
Section section = sectionAndIndex.Key;
int index = sectionAndIndex.Value;
var cell = tableView.CellAt(path);
if (_picker_present)
{
// Remove the picker.
cell.DetailTextLabel.TextColor = UIColor.Gray;
section.Remove(_inline_date_element);
_picker_present = false;
if (PickerClosed != null)
PickerClosed();
}
else
{
// Show the picker.
cell.DetailTextLabel.TextColor = UIColor.Red;
_inline_date_element = new InlineDateElement(DateValue);
_inline_date_element.DateSelected += (DateTime? date) =>
{
this.DateValue = date;
cell.DetailTextLabel.Text = FormatDate(date);
Value = cell.DetailTextLabel.Text;
cell.BackgroundColor = UIColor.FromRGB(1f, 1f, 0.8f);
if (DateSelected != null) // Fire our changed event.
DateSelected();
};
_inline_date_element.ClearPressed += () =>
{
DateTime? null_date = null;
DateValue = null_date;
cell.DetailTextLabel.Text = " ";
Value = cell.DetailTextLabel.Text;
cell.DetailTextLabel.TextColor = UIColor.Gray;
section.Remove(_inline_date_element);
_picker_present = false;
if (PickerClosed != null)
PickerClosed();
cell.BackgroundColor = _defaultColor ?? UIColor.White;
};
section.Insert(index + 1, UITableViewRowAnimation.Bottom, _inline_date_element);
_picker_present = true;
tableView.ScrollToRow(_inline_date_element.IndexPath, UITableViewScrollPosition.None, true);
if (PickerOpened != null)
PickerOpened();
}
}
}
示例8: PrepareEntry
protected virtual void PrepareEntry(UITableView tableview){
SizeF size = _computeEntryPosition(tableview);
_entry = new UITextField (new RectangleF (size.Width+10, (ContentView.Bounds.Height-size.Height)/2-1, 320-size.Width, size.Height));
TextLabel.BackgroundColor = UIColor.Clear;
_entry.AutoresizingMask = UIViewAutoresizing.FlexibleWidth |
UIViewAutoresizing.FlexibleLeftMargin;
_entry.ValueChanged += delegate {
if (_element != null)
_element.Value = _entry.Text;
};
_entry.Ended += delegate {
if (_element != null)
_element.Value = _entry.Text;
};
_entry.AddTarget((object o, EventArgs r)=>{
if (_element != null)
_element.Value = _entry.Text;
}, UIControlEvent.EditingChanged);
_entry.ShouldReturn += delegate {
Element elementToFocusOn = null;
foreach (var c in ((Section)_element.Parent).Elements){
if (c == _element)
elementToFocusOn = c;
else if (elementToFocusOn != null && c is EntryElement)
elementToFocusOn = c as EntryElement;
}
if (elementToFocusOn != _element && elementToFocusOn!=null) {
var index = elementToFocusOn.GetIndexPath();
var cell = tableview.CellAt(index);
tableview.ScrollToRow(index, UITableViewScrollPosition.Bottom, true);
cell.BecomeFirstResponder();
}
else
_entry.ResignFirstResponder();
if (_entry.ReturnKeyType == UIReturnKeyType.Go) {
_element.FireGo(this, EventArgs.Empty);
}
return true;
};
_entry.Started += delegate {
EntryElement self = null;
var returnType = _element.ReturnKeyType;
if (returnType != UIReturnKeyType.Default) {
foreach (var e in (_element.Parent as Section).Elements){
if (e == _element)
self = _element;
else if (self != null && e is EntryElement)
returnType = UIReturnKeyType.Next;
}
}
_entry.ReturnKeyType = returnType;
};
ContentView.AddSubview (_entry);
}
示例9: GetCell
public override UITableViewCell GetCell(UITableView tv)
{
var cell = tv.DequeueReusableCell (CellKey);
if (cell == null){
cell = new UITableViewCell (UITableViewCellStyle.Default, CellKey);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
} else
RemoveTag (cell, 1);
if (entry == null){
SizeF size = ComputeEntryPosition (tv, cell);
float yOffset = (GetHeight(this.GetContainerTableView(), IndexPath) - size.Height) / 2;
float width = cell.ContentView.Bounds.Width - size.Width - 2; // remove two pixels to fix up appearance in case this is the only control in section
entry = CreateTextView (new RectangleF (size.Width, yOffset, width, size.Height));
if (AcceptReturns == false)
entry.ReturnKeyType = UIReturnKeyType.Done;
else
entry.ReturnKeyType = UIReturnKeyType.Default;
entry.KeyboardType = UIKeyboardType.Default;
entry.AutocorrectionType = UITextAutocorrectionType.Default;
entry.Changed += delegate {
FetchValue ();
if (Changed != null)
Changed(this, new EventArgs());
};
entry.Ended += delegate {
FetchValue ();
if (Changed != null)
Changed(this, new EventArgs());
entry.ResignFirstResponder();
this.GetImmediateRootElement().TableView.EndEditing(true);
};
entry.Started += delegate {
tv.ScrollToRow (IndexPath, UITableViewScrollPosition.Middle, true);
};
}
cell.TextLabel.Text = Caption;
cell.ContentView.AddSubview (entry);
return cell;
}
示例10: GetCell
public override UITableViewCell GetCell(UITableView tv)
{
var cell = tv.DequeueReusableCell(CellKey);
if (cell == null)
{
cell = new UITableViewCell(UITableViewCellStyle.Default, CellKey);
cell.SelectionStyle = UITableViewCellSelectionStyle.None;
}
else
RemoveTag(cell, 1);
if (entry == null)
{
SizeF size = ComputeEntryPosition(tv, cell);
float yOffset = (cell.ContentView.Bounds.Height - size.Height) / 2 - 1;
float width = cell.ContentView.Bounds.Width - size.Width;
if (textalignment == UITextAlignment.Right)
{
// Add padding if right aligned
width -= 10;
}
entry = CreateTextField(new RectangleF(size.Width, yOffset, width, size.Height));
entry.ValueChanged += delegate
{
FetchValue();
};
entry.Ended += delegate
{
FetchValue();
if (EntryEnded != null)
{
EntryEnded(this, null);
}
};
entry.ShouldReturn += delegate
{
if (ShouldReturn != null)
return ShouldReturn();
RootElement root = GetImmediateRootElement();
EntryElement focus = null;
if (root == null)
return true;
foreach (var s in root.Sections)
{
foreach (var e in s.Elements)
{
if (e == this)
{
focus = this;
}
else if (focus != null && e is EntryElement)
{
focus = e as EntryElement;
break;
}
}
if (focus != null && focus != this)
break;
}
if (focus != this)
focus.BecomeFirstResponder(true);
else
focus.ResignFirstResponder(true);
return true;
};
entry.Started += delegate
{
EntryElement self = null;
if (EntryStarted != null)
{
EntryStarted(this, null);
}
if (!returnKeyType.HasValue)
{
var returnType = UIReturnKeyType.Default;
foreach (var e in (Parent as Section).Elements)
{
if (e == this)
self = this;
else if (self != null && e is EntryElement)
returnType = UIReturnKeyType.Next;
}
entry.ReturnKeyType = returnType;
}
else
entry.ReturnKeyType = returnKeyType.Value;
tv.ScrollToRow(IndexPath, UITableViewScrollPosition.Middle, true);
//.........这里部分代码省略.........